支持多选功能的 UIImagePickerController 克隆版本。
>= 3.0.0
: iOS 8 或更高版本(使用 PhotoKit)< 3.0.0
: iOS 6 或更高版本(使用 AssetsLibrary)QBImagePickerController *imagePickerController = [QBImagePickerController new];
imagePickerController.delegate = self;
imagePickerController.allowsMultipleSelection = YES;
imagePickerController.maximumNumberOfSelection = 6;
imagePickerController.showsNumberOfSelectedAssets = YES;
[self presentViewController:imagePickerController animated:YES completion:NULL];
QBImagePickerControllerDelegate
方法QBImagePickerController
对象self
设置为 delegate
属性通过使用 presentViewController:animated:completion:
调用显示选择器
QBImagePickerController *imagePickerController = [QBImagePickerController new]; imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:NULL];
实现 qb_imagePickerController:didFinishPickingAssets:
来获得用户所选择的资源。
当用户完成选择资源时,将调用此方法。
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
for (PHAsset *asset in assets) {
// Do something with the asset
}
[self dismissViewControllerAnimated:YES completion:NULL];
}
实现 qb_imagePickerControllerDidCancel:
以在用户点击 "取消" 按钮时收到通知。
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
[self dismissViewControllerAnimated:YES completion:NULL];
}
您可以通过实现以下方法来处理用户选择的更改。
- (BOOL)qb_imagePickerController:(QBImagePickerController *)imagePickerController shouldSelectAsset:(PHAsset *)asset;
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(PHAsset *)asset;
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didDeselectAsset:(PHAsset *)asset;
当 allowsMultipleSelection
为 YES
时,用户可以选择多张照片。
默认值为 NO
。
imagePickerController.allowsMultipleSelection = YES;
您可以使用 minimumNumberOfSelection
和 maximumNumberOfSelection
属性来限制选择数量。
默认值为 0
,表示选择的数量没有限制。
imagePickerController.minimumNumberOfSelection = 3;
imagePickerController.maximumNumberOfSelection = 6;
使用 assetCollectionSubtypes
属性来指定要显示的相册。
以下代码显示了默认值。
imagePickerController.assetCollectionSubtypes = @[
@(PHAssetCollectionSubtypeSmartAlbumUserLibrary), // Camera Roll
@(PHAssetCollectionSubtypeAlbumMyPhotoStream), // My Photo Stream
@(PHAssetCollectionSubtypeSmartAlbumPanoramas), // Panoramas
@(PHAssetCollectionSubtypeSmartAlbumVideos), // Videos
@(PHAssetCollectionSubtypeSmartAlbumBursts) // Bursts
];
相册将按照您指定的顺序显示。
用户的相册始终显示在智能相册之后。
使用 mediaType
来过滤要显示的资产。
默认值为 QBImagePickerMediaTypeAny
。
imagePickerController.mediaType = QBImagePickerMediaTypeVideo;
有一些属性可以显示有用的信息。
imagePickerController.prompt = @"Select the photos you want to upload!";
imagePickerController.showsNumberOfSelectedAssets = YES;
使用 numberOfColumnsInPortrait
和 numberOfColumnsInLandscape
来更改网格大小。
以下代码显示了默认值。
imagePickerController.numberOfColumnsInPortrait = 4;
imagePickerController.numberOfColumnsInLandscape = 7;
版权所有(c)2015 Katsuma Tanaka
在此,任何人获得此软件及相关文档文件的副本(“软件”),自由使用软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许向软件提供副本的个人这样做,但受以下条件限制
上述版权声明和本许可声明应包含在软件的所有副本或实质性部分中。
软件按“原样”提供,不提供任何形式的保证,明示或暗示的,包括但不限于适销性、适用于特定目的和不侵犯第三方权利。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论该责任源于合同、侵权或其他方式,无论源于软件或其使用或其他使用。