1.首先在storyBoard中創(chuàng)建一個button和imageView并添加約束
添加代理方法:
@interface ViewController ()<UINavigationControllerDelegate,
UIImagePickerControllerDelegate>
從storyBoard--imageView中拖拽出來的屬性
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
//從storyBoard--button拖拽出來的點(diǎn)擊方法
- (IBAction)didClickedPickImageButton:(UIButton *)sender {
//創(chuàng)建UIImagePickerController
UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init];
imagePicker.editing = YES;
imagePicker.allowsEditing = YES;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
(從系統(tǒng)相冊中選取照片)
//模態(tài)出相冊界面
[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;
}