DLPhotoPicker

iOS control that allows picking or displaying photos and videos from user's photo library.


License
MIT
Install
pod try DLPhotoPicker

Documentation

DLPhotoPicker

Build Status codecov.io CocoaPods GitHub watchers GitHub stars GitHub forks GitHub issues GitHub license Twitter

iOS control that allows picking or displaying photos and videos from user's photo library.

Installation with CocoaPods

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

Podfile

To integrate DLPhotoPicker into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'DLPhotoPicker'

Then, run the following command:

$ pod install

Screenshot

image image image image image image image image image image image image image image

#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.

Usage

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
}

License

DLPhotoPicker is released under the MIT license. See LICENSE for details.