本文实例为大家分享了iOS实现相册多选图片上传的具体代码,供大家参考,具体内容如下
原理:获取手机里的全部照片,显示在自定义的视图里
//获取到相册的所有图片 - (void)addAllPhotos{ @WeakObj(self); _assetsLibrary=[[ALAssetsLibrary alloc]init]; [_assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) { @StrongObj(self); if (group) { [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { if (result) { // 把相册储存到数组中,方便后面展示相册时使用 CGImageRef cgImage = [result thumbnail]; UIImage *image = [UIImage imageWithCGImage:cgImage]; NSData *imageData = UIImageJPEGRepresentation(image,0.5); UIImage *newImage = [UIImage imageWithData:imageData]; UZGPhotoChooseModel *model=[[UZGPhotoChooseModel alloc]init]; model.image=newImage; model.currentImageIsSelect=NO;//初始化默认未选中 model.showBackView=NO;//是否显示背景遮罩 model.row=index; [self.cellInfoArray addObject:model]; [self.myCollectionView reloadData]; } }]; } } failureBlock:^(NSError *error) { }]; } //选中图片后刷新图片上面的选中数字 - (selectCellBolck)reloadCellSelectBlock:(NSIndexPath *)indexPath{ @WeakObj(self); __block UZGPhotoChooseModel *model=self.cellInfoArray[indexPath.row]; selectCellBolck block=^(BOOL current_isSelect){ if (selfWeak.selectNum>self.max_selectNum) { return; } if (current_isSelect) { selfWeak.selectNum++; }else{ selfWeak.selectNum--; } model.currentImageIsSelect=current_isSelect; model.totalNum=selfWeak.selectNum; [selfWeak.cellInfoArray replaceObjectAtIndex:indexPath.row withObject:model]; [selfWeak reloadCurrentNum]; [selfWeak.myCollectionView reloadData]; }; return block; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持菜鸟教程(cainiaojc.com)。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#cainiaojc.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。