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 ...
随机推荐
- linux下的oracle11gR2静默安装,经验分享
说明: 1.我的linux是64位的redhat6.5,安装的oracle版本是11.2.0的. 2.我这是自己安装的linux虚拟机,主机名为ora11g,ip为192.168.100.122 3. ...
- 2015年10月15日学习html基础笔记
一个互联网公司的分工,小公司要求全能,拿一个项目全部做出来.大公司分工明细,主要步奏为策划人员策划方案,美工人员设计图有.psd.rp等,前端人员做静态页面,后台人员获取数据java php .net ...
- Educational Codeforces Round 9 -- A - Grandma Laura and Apples
题意: 外祖母要卖苹果,(有很多但不知道数量),最终所有苹果都卖光了! 有n个人买苹果,如果那个人是half,他就买所有苹果的一半,如果那个人是halfplus,则他买当前苹果数量的一半,Laura还 ...
- Polya定理
http://www.cnblogs.com/wenruo/p/5304698.html 先看 Polya定理,Burnside引理回忆一下基础知识.总结的很棒. 一个置换就是集合到自身的一个双射,置 ...
- hdu5601-N*M bulbs(黑白棋盘染色)
一个矩形,一个人从左上角走到右下角,每走过一个位置把0变成1,1变成0. 求有没有可能他离开之后所有的数都是0 假设这个矩形是一个棋盘,黑白相间. 这样会发现从一个颜色走到相同颜色可以对棋盘不产生任何 ...
- Robot Framework自动化测试(二)第一个用例
RIDE启动界面: 首先创建一个Test project File-New Project ,选择Directory类型 在创建的文件夹上右键,创建一个Test Suite Openbaidu, NE ...
- Symfony VarDumper Component
Symfony VarDumper 类似 php var_dump() 官方文档写的安装方法 : 按照步骤 就可以在 running any PHP code 时候使用了 In order to h ...
- NAS、DAS和SAN三种存储究竟是什么?
首先,NAS(Network Attached Storage,网络附加存储)全面改进了以前低效的DAS存储方式,它是采用独立于PC服务器,单独为网络数据存储而开发的一种文件服务器. NAS服务器中集 ...
- iOS 基础知识
1获取系统语言设置 NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSArray *languages = ...
- YII2安装中遇到的错误解决Calling unknown method: yii\web\UrlManager::addRules()
安装好YII2 后出现 例如以下图错误提示: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvenF0c3g=/font/5a6L5L2T/fontsize/ ...