自己总结的修改头像的方法,只为方便自己查询使用!转发

步骤:1、遵守代理协议

<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>

2、点击事件{

UIActionSheet *choosePhotoActionSheet;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

choosePhotoActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"选取图片", @"")

delegate:self

cancelButtonTitle:NSLocalizedString(@"取消", @"")

destructiveButtonTitle:nil

otherButtonTitles:NSLocalizedString(@"相机", @""), NSLocalizedString(@"相册", @""), nil];

} else {

choosePhotoActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"选取图片", @"")

delegate:self

cancelButtonTitle:NSLocalizedString(@"取消", @"")

destructiveButtonTitle

:nil

otherButtonTitles:NSLocalizedString(@"相册", @""), nil];

}

[choosePhotoActionSheet showInView:self.view];

}

3、实现代理方法

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

NSUInteger sourceType = 0;

if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

switch (buttonIndex) {

case 0:

sourceType = UIImagePickerControllerSourceTypeCamera;

break;

case 1:

sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

break;

case 2:

return;

}

} else {

if (buttonIndex == 1) {

return;

} else {

sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

}

}

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

imagePickerController.delegate = self;

imagePickerController.allowsEditing = YES;

imagePickerController.sourceType = sourceType;

[self presentViewController:imagePickerController animated:YES completion:^{

}];

}

#pragma mark - UIImagePickerControllerDelegate

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

{

[self dismissViewControllerAnimated:YES completion:^{

}];

self.tmpHeaderImg = [info objectForKey:UIImagePickerControllerEditedImage];

[self.imageViewUserHead setImage:self.tmpHeaderImg];

[self uploadImage];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

[self dismissViewControllerAnimated:YES completion:^{

}];

}

iOS imagePicker使用方法,方便使用!三步轻松搞定!的更多相关文章

  1. 三步轻松搞定delphi中CXGRID手动添加复表头(多行表头,报表头)

    网上有代码动态生成cxgrid多行表头的源码,地址为:http://mycreature.blog.163.com/blog/static/556317200772524226400/ 如果要手动设计 ...

  2. 3步轻松搞定Spring Boot缓存

    作者:谭朝红 前言 本次内容主要介绍基于Ehcache 3.0来快速实现Spring Boot应用程序的数据缓存功能.在Spring Boot应用程序中,我们可以通过Spring Caching来快速 ...

  3. Webcast / 技术小视频制作方法——自己动手录制video轻松搞定

    Webcast / 技术小视频制作方法——自己动手录制video轻松搞定 http://blog.sina.com.cn/s/blog_67d387490100wdnh.html 最近申请加入MSP的 ...

  4. PDF怎么旋转页面,只需几步轻松搞定!

    有时候我们下载一个PDF文件里面有页面是旋转的情况,用手机看的时候可以把手机旋转过来看,那么用电脑的时候总不可能也转过来看吧,笔记本是可以的台式的是不行的,这个时候我们就需要把PDF文件中旋转的页面转 ...

  5. Python高级特性: 12步轻松搞定Python装饰器

    12步轻松搞定Python装饰器 通过 Python 装饰器实现DRY(不重复代码)原则:  http://python.jobbole.com/84151/   基本上一开始很难搞定python的装 ...

  6. 爬虫工程师分享:三步就搞定 Android 逆向

    本文源于我近期的一次公司内部分享,通过逆向某款 APP 来介绍逆向过程.由于仅作为学习用途,APP 的相关信息会被遮盖,敬请理解. 关于逆向 逆向--包括但不限于通过反编译.Hook 等手段,来解析一 ...

  7. java web每天定时执行任务(四步轻松搞定)

    第一步: package com.eh.util; import java.util.Calendar; import java.util.Date; import java.util.Timer; ...

  8. 转载 12步轻松搞定python装饰器

    作者: TypingQuietly 原文链接: https://www.jianshu.com/p/d68c6da1587a 呵呵!作为一名教python的老师,我发现学生们基本上一开始很难搞定pyt ...

  9. 12步轻松搞定Python装饰器

    译者:寒寻 译文:http://www.cnblogs.com/imshome/p/8327438.html 原文:https://dzone.com/articles/understanding-p ...

随机推荐

  1. md5可能会被破解咋办?

    所谓加Salt,就是加点“佐料”.其基本想法是这样的——当用户首次提供密码时(通常是注册时),由系统自动往这个密码里撒一些“佐料”,然后再散列.而当用户登录时,系统为用户提供的代码撒上同样的“佐料”, ...

  2. 委托demo

    delegate bool Filter(string s); class test { static void Main() { Filter f=new Filter(A); Display(ne ...

  3. poj 3984 迷宫问题【bfs+路径记录】

    迷宫问题 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10103   Accepted: 6005 Description ...

  4. time_t和struct tm之间的转换

    time_t到struct tm的转换: #include <time.h> struct tm *localtime(const time_t *timep); struct tm到ti ...

  5. spring mvc Spring Data Redis RedisTemplate [转]

    http://maven.springframework.org/release/org/springframework/data/spring-data-redis/(spring-data包下载) ...

  6. 第一篇:GPU 编程技术的发展历程及现状

    前言 本文通过介绍 GPU 编程技术的发展历程,让大家初步地了解 GPU 编程,走进 GPU 编程的世界. 冯诺依曼计算机架构的瓶颈 曾经,几乎所有的处理器都是以冯诺依曼计算机架构为基础的.该系统架构 ...

  7. Building and setting up QT environment for BeagleBone

    There are too few information available on how to easily setup QT environment for building Beaglebon ...

  8. 集合练习——List部分

    利用ArrayList 1.存储多个员工信息,包括工号,姓名,年龄,入职时间,逐条打印所有员工姓名,并输出员工个数. package CollectionPart; import java.util. ...

  9. bit,byte,char,string区别与基本类型认识

    bit.byte.位.字节.汉字的关系 1 bit     = 1  二进制数据        1 byte  = 8  bit        1 字母 = 1  byte = 8 bit       ...

  10. [Form Builder]APP_ITEM_PROPERTY.SET_PROPERTY 用法

    ORACLE 推荐使用此种方法来控制ITEM属性,虽然实质也是调用set_item_instance_property和set_item_property ALTERABLE app_item_pro ...