iOS從相冊和相機選擇圖片進行封裝
iOS從相冊和相機選擇圖片進行封裝,從相冊支持選擇多張和一張控制,集成使用簡單方便,具體看demo使用集成方式。
接口使用實例
Use Example
- (IBAction)clickButton:(UIButton *)sender{ switch (sender.tag) { case 0:{//從相冊選擇一張 WHC_PictureListVC * vc = [WHC_PictureListVC new]; vc.delegate = self; vc.choiceMorePicture = NO; [self presentViewController:[[UINavigationController alloc]initWithRootViewController:vc] animated:YES completion:nil]; } break; case 1:{//從相冊選擇多張 WHC_PictureListVC * vc = [WHC_PictureListVC new]; vc.delegate = self; vc.choiceMorePicture = YES; [self presentViewController:[[UINavigationController alloc]initWithRootViewController:vc] animated:YES completion:nil]; } break; case 2:{//從相機選擇 WHC_CameraVC * vc = [WHC_CameraVC new]; vc.delegate = self; [self presentViewController:vc animated:YES completion:nil]; } break; default: break; } } //下面是代理實現在代理里面顯示所選圖片 #pragma mark - WHC_ChoicePictureVCDelegate - (void)WHCChoicePictureVC:(WHC_ChoicePictureVC *)choicePictureVC didSelectedPhotoArr:(NSArray *)photoArr{ for (UIView * subView in _imageSV.subviews) { if([subView isKindOfClass:[UIImageView class]]){ [subView removeFromSuperview]; } } for (NSInteger i = 0; i < photoArr.count; i++) { UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(i * CGRectGetWidth(_imageSV.frame), 0, CGRectGetWidth(_imageSV.frame), CGRectGetHeight(_imageSV.frame))]; imageView.image = photoArr[i]; [_imageSV addSubview:imageView]; } _imageSV.contentSize = CGSizeMake(photoArr.count * CGRectGetWidth(_imageSV.frame), 0); } #pragma mark - WHC_CameraVCDelegate - (void)WHCCameraVC:(WHC_CameraVC *)cameraVC didSelectedPhoto:(UIImage *)photo{ [self WHCChoicePictureVC:nil didSelectedPhotoArr:@[photo]]; }
本文由用戶 cf35 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!