码迷,mamicode.com
首页 > 其他好文 > 详细

UIImagePickerController

时间:2015-09-09 21:15:32      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

//从相册里面选择照片

-(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];

}

 

UIImagePickerController

标签:

原文地址:http://www.cnblogs.com/xzguo/p/4795740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!