1 用途: 是系统提供的用来获取图片和视频的接口;
2获取图片途径:拍照,图库,相册获取
enum {
UIImagePickerControllerSourceTypePhotoLibrary ,
//来自图库
UIImagePickerControllerSourceTypeCamera ,
//来自相机
UIImagePickerControllerSourceTypeSavedPhotosAlbum
//来自相册
};
3 步骤:
初始化一个UIImagePickerController类
设置数据来源类型,—— 上面2
设置代理
如果需要对图片进行修改,allowsEditing = yes
4 具体代码实现
#pragma mark 选择图片
- (IBAction)selectImage:(UITapGestureRecognizer *)sender{
//图片选择控制器
UIImagePickerController *pickerController=[[UIImagePickerController alloc] init];
//选择你要使用的类型 图集,相册,相机 pickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.delegate=self;
pickerController.allowsEditing=YES;
[self presentViewController:pickerController animated:YES completion:nil];
}
#pragma mark delegate
-(void)p_w_picpathPickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
//根据选择的图片 设置头像
_IconImage.p_w_picpath=info[@"UIImagePickerControllerOriginalImage"];
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
转载于:https://blog.51cto.com/mengxiang8/1745697