DLPhotoPicker 2.1.2

DLPhotoPicker 2.1.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2019年9月

darling0825 维护。



 
依赖
PureLayout~> 3.0.0
SVProgressHUD>= 0
TOCropViewController>= 0
 

  • darling0825

DLPhotoPicker

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

iOS 控件,允许从用户的照片库中选择或显示照片和视频。

使用 CocoaPods 安装

CocoaPods 是一个 Objective-C 的依赖管理器,自动化和简化了在项目中使用如 DLPhotoPicker 等第三方库的过程。您可以使用以下命令安装它:

$ gem install cocoapods

Podfile

要使用 CocoaPods 将 DLPhotoPicker 集成到您的 Xcode 项目中,请在 Podfile 中指定它

pod 'DLPhotoPicker'

然后,运行以下命令

$ pod install

截图

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

特性

  • 支持 AssetsLibrary(iOS7) 和 Photos(iOS 8 或更高版本) 框架。
  • 支持图片显示、编辑和选择。
  • 支持将照片保存到相册和保存到应用程序沙盒文档。

使用

首先导入头文件:DLPhotoPicker.h

显示所有相册和照片。

- (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];
  }

从相册中选取照片或视频。

- (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];
}

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遵循MIT许可证发布。详情见LICENSE文件。