iOS control that allows picking or displaying photos and videos from user's photo library.
CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like DLPhotoPicker in your projects. You can install it with the following command:
$ gem install cocoapods
To integrate DLPhotoPicker into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'DLPhotoPicker'
Then, run the following command:
$ pod install
#Features
- Support AssetsLibrary(iOS7) and Photos(iOS 8 or later) framework.
- Support photo display, edit and pick.
- Suppert save the photo to a album and save to document of app sandbox.
First import header file: DLPhotoPicker.h
To display all albums and photos.
- (IBAction)clickPhotoDisplayAction:(id)sender
{
DLPhotoPickerViewController *picker = [[DLPhotoPickerViewController alloc] init];
picker.delegate = self;
picker.pickerType = DLPhotoPickerTypeDisplay;
picker.showsNumberOfAssets = YES;
picker.navigationTitle = NSLocalizedString(@"Albums", nil);
[self presentViewController:picker animated:YES completion:nil];
}
To pick photo or video from photo library.
- (void)pickAssets:(id)sender
{
DLPhotoPickerViewController *picker = [[DLPhotoPickerViewController alloc] init];
picker.delegate = self;
picker.pickerType = DLPhotoPickerTypePicker;
picker.navigationTitle = NSLocalizedString(@"Albums", nil);
[self presentViewController:picker animated:YES completion:nil];
}
The Delegate of DLPhotoPicker
-(void)pickerController:(DLPhotoPickerViewController *)picker didFinishPickingAssets:(NSArray *)assets
{
[self dismissViewControllerAnimated:YES completion:nil];
self.assets = [NSArray arrayWithArray:assets];
// to operation with 'self.assets'
}
- (BOOL)pickerController:(DLPhotoPickerViewController *)picker shouldScrollToBottomForPhotoCollection:(DLPhotoCollection *)assetCollection;
{
return YES;
}
- (BOOL)pickerController:(DLPhotoPickerViewController *)picker shouldEnableAsset:(DLPhotoAsset *)asset
{
return YES;
}
- (BOOL)pickerController:(DLPhotoPickerViewController *)picker shouldSelectAsset:(DLPhotoAsset *)asset
{
NSInteger max = 10;
if (picker.selectedAssets.count >= max){
UIAlertController *alert =
[UIAlertController alertControllerWithTitle:@"Attention"
message:[NSString stringWithFormat:@"Please select not more than %ld assets", (long)max]
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action =
[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:nil];
[alert addAction:action];
[picker presentViewController:alert animated:YES completion:nil];
}
// limit selection to max
return (picker.selectedAssets.count < max);
return YES;
}
- (void)pickerController:(DLPhotoPickerViewController *)picker didSelectAsset:(DLPhotoAsset *)asset
{
// didSelectAsset
}
- (BOOL)pickerController:(DLPhotoPickerViewController *)picker shouldDeselectAsset:(DLPhotoAsset *)asset
{
return YES;
}
- (void)pickerController:(DLPhotoPickerViewController *)picker didDeselectAsset:(DLPhotoAsset *)asset
{
// didDeselectAsset
}
- (BOOL)pickerController:(DLPhotoPickerViewController *)picker shouldHighlightAsset:(DLPhotoAsset *)asset
{
return YES;
}
- (void)pickerController:(DLPhotoPickerViewController *)picker didHighlightAsset:(DLPhotoAsset *)asset
{
// didHighlightAsset
}
DLPhotoPicker is released under the MIT license. See LICENSE for details.