您的位置:首页 > 移动开发 > IOS开发

IOS获取系统相册图片

2017-05-17 23:12 387 查看
获取系统相册图片,首先遵守代理协议

@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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: