获取系统相册图片,首先遵守代理协议
@interface ViewController ()<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@end
添加点击事件
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UIImagePickerController *vc = [UIImagePickerController new];
//有三种 照相机 文件夹 相册
// vc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
vc.delegate = self;
vc.allowsEditing = YES;
[self presentViewController:vc animated:YES completion:nil];
}
选择图片后 要做的事 实现在代理方法中
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
NSLog(@"%@",info);
UIImage *image= info[@"UIImagePickerControllerEditedImage"];
UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];
iv.image = image;
[self.view addSubview:iv];
[self dismissViewControllerAnimated:YES completion:nil];
}
接下来一起去看下效果吧!
看完单选图片,一起看一下更常用的多选系统相册图片吧:
http://blog.csdn.net/lee727n/article/details/72455769