1.首先在storyBoard中创建一个button和imageView并添加约束
FD816A1E-516A-44BD-901B-81B8B9A0BFC4.png
添加代理方法:
@interface ViewController ()<UINavigationControllerDelegate,
UIImagePickerControllerDelegate>
从storyBoard--imageView中拖拽出来的属性
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
//从storyBoard--button拖拽出来的点击方法
- (IBAction)didClickedPickImageButton:(UIButton *)sender {
//创建UIImagePickerController
UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
imagePicker.editing = YES;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
(从系统相册中选取照片)
//模态出相册界面
[self presentViewController:imagePicker animated:YES completion:nil];
}
//使用选取的图片:
-(void)imagePickerController:(UIImagePickerController *)
picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage * selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
self.imageView.image = selectedImage;
}
屏幕快照 2016-04-27 下午7.52.25.png
屏幕快照 2016-04-27 下午7.52.36.png
屏幕快照 2016-04-27 下午7.52.45.png
屏幕快照 2016-04-27 下午7.57.46.png
屏幕快照 2016-04-27 下午7.57.52.png
屏幕快照 2016-04-27 下午7.57.58.png
网友评论