标签:
//从相册里面选择照片
-(void)selectPhoto
{
// 1.创建UIImagePickerController
UIImagePickerController *pickerVc = [[UIImagePickerController alloc]init];
// 2.设置从相册选择照片
pickerVc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 3.设置委托
pickerVc.delegate = self;
// 4.是否允许编辑
pickerVc.allowsEditing = YES;
[self presentViewController:pickerVc animated:YES completion:nil];
}
//拍照
-(void)takePhoto
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// 支持拍照
// 1.创建UIImagePickerController
UIImagePickerController *pickerVc = [[UIImagePickerController alloc]init];
// 2.设置从相机选择照片
pickerVc.sourceType = UIImagePickerControllerSourceTypeCamera;
// 3.设置委托
pickerVc.delegate = self;
// 4.是否允许编辑
pickerVc.allowsEditing = YES;
[self presentViewController:pickerVc animated:YES completion:nil];
}else{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"本机不支持拍照" message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
[alertView show];
}
}
//从相册里面选择照片
-(void)selectPhoto
{
// 1.创建UIImagePickerController
UIImagePickerController *pickerVc = [[UIImagePickerController alloc]init];
// 2.设置从相册选择照片
pickerVc.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 3.设置委托
pickerVc.delegate = self;
// 4.是否允许编辑
pickerVc.allowsEditing = YES;
[self presentViewController:pickerVc animated:YES completion:nil];
}
//照片选择回到方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
_imageView.image = image;
[picker dismissViewControllerAnimated:YES completion:nil];
}
标签:
原文地址:http://www.cnblogs.com/xzguo/p/4795740.html