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

步骤: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. cloudstack安装篇3-SELinux配置、NTP时间同步、配置ClouStack软件库

    一.SELinux配置 为了让CloudStack正常工作,我们必须将SELinux设置为permissive.需要在当前系统运行状态下和启动后都能够生效,进行以下配置. 在系统运行状态下的将SELi ...

  2. 为静态Checkbox动态地添加checked属性

    1.ASP.NET HTML Code: 嵌套在repeater中 " ? "checked" : "" %> /> *** 关键代码: ...

  3. Devlop Win 8 and Windows Phone App for Microsoft Dynamics CRM

    Microsoft Dynamics CRM App for Windows Phone http://www.windowsphone.com/en-us/store/app/dynamics-cr ...

  4. 解决IE下iframe默认有白色背景的bug

    又是一个IE莫名其妙的bug:做了一个弹出层,层里面是一张透明图片,IE下的iframe默认会有一个白色的背景,所以当iframe的外围背景并不是白色的时候,这个iframe就会显得非常的“与众不同” ...

  5. 冒泡排序和快速排序的java实现

    转发请注明原创地址 http://www.cnblogs.com/dongxiao-yang/p/6264831.html 冒泡 public static int[] bubble_sort(int ...

  6. UAF漏洞--iOS是越狱原理

    Use After Free UAF 就是 Use After Free的缩写,是一种比较常见的内存错误式利用.很多iOS的越狱都是利用的这种方法.在此简单的举个例子说明UAF出现的情况 代码说明一切 ...

  7. 跑马灯效果的TextView之singLine 和maxLines

    Android 的TextView 里面有两个属性 singLine 和maxLines . 从字面意思来理解,这两个都是限制Text的行数.那么singleLine="true" ...

  8. 每天进步一点达——MySQL——myisampack

    一.        简单介绍 myisampack是一个压缩使用MyISAM引擎表的工具,通常会压缩40%~70%,当须要訪问数据.server会将所须要的信息读入到内存中.所以当訪问详细记录时,性能 ...

  9. jQuery获取Select选中的Text和Value,根据Value值动态添加属性

    语法解释:1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发2. var chec ...

  10. 判断2D平面内某点是否在某个旋转的矩形(OBB)内的算法

    http://stackoverflow.com/questions/7328424/point-in-obb-oriented-bounding-box-algorithm Given a cent ...