iOS imagePicker使用方法,方便使用!三步轻松搞定!
自己总结的修改头像的方法,只为方便自己查询使用!转发
步骤: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使用方法,方便使用!三步轻松搞定!的更多相关文章
- 三步轻松搞定delphi中CXGRID手动添加复表头(多行表头,报表头)
网上有代码动态生成cxgrid多行表头的源码,地址为:http://mycreature.blog.163.com/blog/static/556317200772524226400/ 如果要手动设计 ...
- 3步轻松搞定Spring Boot缓存
作者:谭朝红 前言 本次内容主要介绍基于Ehcache 3.0来快速实现Spring Boot应用程序的数据缓存功能.在Spring Boot应用程序中,我们可以通过Spring Caching来快速 ...
- Webcast / 技术小视频制作方法——自己动手录制video轻松搞定
Webcast / 技术小视频制作方法——自己动手录制video轻松搞定 http://blog.sina.com.cn/s/blog_67d387490100wdnh.html 最近申请加入MSP的 ...
- PDF怎么旋转页面,只需几步轻松搞定!
有时候我们下载一个PDF文件里面有页面是旋转的情况,用手机看的时候可以把手机旋转过来看,那么用电脑的时候总不可能也转过来看吧,笔记本是可以的台式的是不行的,这个时候我们就需要把PDF文件中旋转的页面转 ...
- Python高级特性: 12步轻松搞定Python装饰器
12步轻松搞定Python装饰器 通过 Python 装饰器实现DRY(不重复代码)原则: http://python.jobbole.com/84151/ 基本上一开始很难搞定python的装 ...
- 爬虫工程师分享:三步就搞定 Android 逆向
本文源于我近期的一次公司内部分享,通过逆向某款 APP 来介绍逆向过程.由于仅作为学习用途,APP 的相关信息会被遮盖,敬请理解. 关于逆向 逆向--包括但不限于通过反编译.Hook 等手段,来解析一 ...
- java web每天定时执行任务(四步轻松搞定)
第一步: package com.eh.util; import java.util.Calendar; import java.util.Date; import java.util.Timer; ...
- 转载 12步轻松搞定python装饰器
作者: TypingQuietly 原文链接: https://www.jianshu.com/p/d68c6da1587a 呵呵!作为一名教python的老师,我发现学生们基本上一开始很难搞定pyt ...
- 12步轻松搞定Python装饰器
译者:寒寻 译文:http://www.cnblogs.com/imshome/p/8327438.html 原文:https://dzone.com/articles/understanding-p ...
随机推荐
- java md5方法 for Android
很简单的方法 public static String md5(String string) { byte[] hash; try { hash = MessageDigest.getInstance ...
- 重装mysql步骤
, 卸载MySQL 2, 删除目录 C:\Documents and Settings\All Users\Application Data\MySQL (这个真的有,原先没注意到,删掉!) 如果没有 ...
- NOIP2015 斗地主(搜索+剪枝)
4325: NOIP2015 斗地主 Time Limit: 30 Sec Memory Limit: 1024 MBSubmit: 270 Solved: 192[Submit][Status] ...
- SNMP: Simple? Network Management Protocol(转)
转自:http://www.rane.com/note161.html An SNMP Overview The Message Format The Actual Bytes Introductio ...
- JS多态
面向对象语言有三大特征,前面介绍了封装和继承,那么JS作为一门面向对象语言,有多态么,又怎么实现多态呢? 我们先看看多态的概念: 多态:同一操作作用于不同的对象,可以有不同的解释,产生不同的执行结果. ...
- Maven管理项目架包
最近一直在用Maven管理项目的架包,从而发现了几个不错的官方或者非官方的网站. http://mvnrepository.com/artifact/com.ning 这个是我刚刚用来找HTTP开发 ...
- HDU5100Chessboard(数论)
HDU5100Chessboard(数论) 题目链接 题目大意:用k∗1的瓷砖区铺n∗n的矩形,问能铺上的最大的面积. 解题思路:这题没有直接得出结论:l = n%k, ans = max[(n^2 ...
- C#获取内存图像数据流的方法
背景:有的时候我们已经得到一个图像的内存对象,如Bitmap对象,我们想要获取到这个对象的数据流,可以将其序列化到磁盘上,并且也可以反序列化为内存对象,这个时候就有了如题的问题出现,我搜遍全网就是没有 ...
- 使用split进行分割时遇到特殊字符的问题
使用split分割时: String[] a="aa|bb|cc".split("|"); output: [a, a, |, b, b, |, c, c] 先 ...
- 判断URL是否存在
判断URL是否存在 判断网址是否存在,可以使用下面方面处理.如果HttpStatusCode为OK,说明网址存在.