- (IBAction)tapImageView:(id)sender {
// 从相册里选图片
// 1.判断数据源是否可用
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// 2.创建图片选择器
UIImagePickerController *pickerVC = [[UIImagePickerController alloc] init];
pickerVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 3.设置代理
pickerVC.delegate = self;
//4.显示图片选择器
[self presentViewController:pickerVC animated:YES completion:nil];
}
}
#pragma mark - UIImagePickerController的代理
// 选完图片后调用这个方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// 1.取出选中的图片
UIImage *image = info[UIImagePickerControllerOriginalImage];
// 2.设置图片到imageview上
self.imageView.image = image;
// 3,关闭图片选择器
[picker dismissViewControllerAnimated:YES completion:nil];
}