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 ...
随机推荐
- 跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量
跟我学机器视觉-HALCON学习例程中文详解-IC引脚测量 Lead Measurement: Example for the application of the measure object in ...
- Linux中的权限管理
touch 11.txt(创建了一个文件) chown zhangsan:zhangsan 11.txt ll(可看到11.txt的属主和属组都改为了zhangsan) useradd lisi(添加 ...
- LittleTools之输出RenderTexture工具
using UnityEngine; using System.Collections; using System.IO; /// <summary> /// Save render te ...
- linux进程的几种状态
Linux是一个多用户,多任务的系统,可以同时运行多个用户的多个程序,就必然会产生很多的进程,而每个进程会有不同的状态. Linux进程状态:R (TASK_RUNNING),可执行状态. 只有在该状 ...
- Clean Code – Chapter 3: Functions
Small Blocks and Indenting The blocks within if statements, else statements, while statements, and s ...
- Kooboo 加Search功能 必须先ReBuild Index Data
加Search功能 有几个要点 1. 需要在Kooboo 必须先 ReBuild Index Data 2. 需要在要搜索的page中启用搜索索引 搜索的代码 @using K ...
- Win8关机 一直重启的问题 解决方案-摘自网络
win8关机时自动重启的解决方法:关闭快递启动,默认是启动的,到控制面板 – 电源选项 – 选择电源按钮的功能 – 更改当前不可用的设置 – 关机设置 – 把勾去掉 关闭快速启动.这样就不会关机一直重 ...
- ios:Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)laun ...
- T-SQL语句查看作业等信息
因服务器需要迁移,需要将现有JOB迁移至新服务器,待服务器调整完毕,则重新迁移到原服务器,所以在做迁移之前希望将现有JOB进行备份,不至于乱了执行时间.1.查看所有作业列表USE master SEL ...
- DoctorNote医生处方笔记开发记录
1.开发背景 一个开诊所的中医朋友,希望我能给他开发一个记录病人姓名和处方的Android手机app,以便查询病人每次就诊信息,比如上一次的处方,以前他要找个病人上一次的就诊处方,几乎要翻遍一叠厚厚的 ...