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

  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;

}

转载于:https://www.cnblogs.com/yyt-hehe-yyt/p/5276391.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值