支持多选的 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
任何人获得此软件及其相关文档副本(以下简称“软件”)的副本,在此授予免费使用软件的权利,不包括但不限于使用、复制、修改、合并、发布、分发、转授权和/或销售软件副本的权利,以及允许获得软件的个人进行上述操作的权利,前提是必须遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分。
本软件按“原样”提供,不提供任何形式的保证,包括但不限于对适销性、特定用途适用性和不侵权的保证。在任何情况下,作者或版权持有人不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他方式引起的,无论源自、因之而产生或与此软件或软件的使用或其他操作相关。