码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发——打开手机相册,获取图片

时间:2016-03-14 18:44:52      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

  1.添加代理UIImagePickerControllerDelegate

  2.设置点击跳转事件

- (IBAction)picButton:(UIButton *)sender {

    NSLog(@"我的相册");

    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){

        //a.初始化相册拾取器

        UIImagePickerController *controller = [[UIImagePickerController alloc] init];

        //b.设置代理

        controller.delegate = self;

        //c.设置资源:

        /**

         UIImagePickerControllerSourceTypePhotoLibrary,相册

         UIImagePickerControllerSourceTypeCamera,相机

         UIImagePickerControllerSourceTypeSavedPhotosAlbum,照片库

         */

        controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

        //d.随便给他一个转场动画

        controller.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;

        [self presentViewController:controller animated:YES completion:NULL];

        

    }else{

        

        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"设备不支持访问相册,请在设置->隐私->照片中进行设置!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];

        [alert show];

    }

}

 

  3.获取图片

#pragma mark-> imagePickerController delegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

    //a.获取选择的图片

    UIImage *image = info[UIImagePickerControllerOriginalImage];

    self.imageView.image = image;

}

iOS开发——打开手机相册,获取图片

标签:

原文地址:http://www.cnblogs.com/yyt-hehe-yyt/p/5276391.html

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