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

调用相册资源

时间:2015-11-04 17:40:31      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

 

目标类需要确认的协议

@interface AddViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate>

 

1. //给头像图片添加一个处理事件

    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dddd)];

    self.myiamge.userInteractionEnabled = YES;

    [self.myiamge addGestureRecognizer:tap];

 

2,//点击头像图片的处理方法

-(void)dddd

{

    //弹出系统提供的相册,UIimagepickerviewcontroller

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])

    {

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

        picker.delegate= self;

        //指定源为相册

        picker .sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentViewController:picker  animated:YES completion:nil];

    }

 

}

3,//代理方法,当点击相册中的某张图片时调用

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

{

    //获取图片,从字典中

    self.myiamge.image = info[UIImagePickerControllerOriginalImage];

    [picker dismissViewControllerAnimated:YES completion:nil];

    

    

}

调用相册资源

标签:

原文地址:http://www.cnblogs.com/liuzhongblog/p/4936567.html

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