图片选择器QBImagePickerController的使用

cocoaPod导入QBImagePickerController
头文件导入#import
遵循协议QBImagePickerControllerDelegate

1,创建一个图片选择器

QBImagePickerController *imagePC = [QBImagePickerController new];
        imagePC.delegate = self;
        imagePC.allowsMultipleSelection = YES;
        imagePC.showsNumberOfSelectedAssets = YES;
        imagePC.maximumNumberOfSelection = 1;
        imagePC.mediaType = QBImagePickerMediaTypeImage;
        [self presentViewController:imagePC animated:YES completion:nil];

实现代理方法,主要是获取图片的方式
#pragma mark -- QBImagePickerControllerDelegate
- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets {
//获取图片
PHAsset *asset = [assets firstObject];
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:nil resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
_image1 = result;
}];

[self dismissViewControllerAnimated:YES completion:nil];
}

//使点击返回能够有效
- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController {
[self dismissViewControllerAnimated:YES completion:nil];
}

你可能感兴趣的:(图片选择器QBImagePickerController的使用)