IOS开发之——保存图片到相册的功能实现
//保存
UIButton *saveBtn = [[UIButton alloc] init];
// saveBtn.frame = CGRectMake((screenWidth-270)/4+1, 550/9*screenScale + 272/9*screenScale + 128/9*screenScale + 172/9*screenScale + 55,133, 42);
saveBtn.frame = CGRectMake((screenWidth-270)/4+1,1766/3,133, 42);
[saveBtn setTitle:@"保存" forState:UIControlStateNormal];
[saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[saveBtn setBackgroundColor:[UIColor colorWithRed:58/256.0 green:150/256.0 blue:253/256.0 alpha:1.0f]];
[saveBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
saveBtn.titleLabel.font = [UIFont systemFontOfSize:17];
[self.view addSubview:saveBtn];
-(void)save
{
NSLog(@"---save");
// //如果你的系统大于等于7.0 >
// if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
//
// UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:@"保存二维码到相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
// alertView.tag = 1;
// [alertView show];
//
// }else{
//
// //>=iOS8以上才有alertController这个方法
// UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:@"保存二维码到相册" preferredStyle:UIAlertControllerStyleAlert];
// UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
// UIImageWriteToSavedPhotosAlbum(_codeView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
// }];
//
// UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//
// }];
//
// [alertController addAction:cancelAction];
// [alertController addAction: okAction];
// [self presentViewController:alertController animated:YES completion:nil];
//
//}
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"" message:@"保存二维码到相册" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
alertView.tag = 1;
[alertView show];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
if (error == nil) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"已存入手机相册" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定",nil];
alertView.tag = 2;
[alertView show];
}else{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"请去设置-隐私-照片打开允许访问" message:@"保存失败" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
alertView.tag = 3;
[alertView show];
}
}
#pragma mark uialertview deleagate
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0 && alertView.tag ==1) {
UIImageWriteToSavedPhotosAlbum(_codeView.image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}else if(buttonIndex == 0 && alertView.tag==3){
//打开设置-隐私-照片
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
IOS开发之——保存图片到相册的功能实现的更多相关文章
- IOS开发-OC学习-常用功能代码片段整理
IOS开发-OC学习-常用功能代码片段整理 IOS开发中会频繁用到一些代码段,用来实现一些固定的功能.比如在文本框中输入完后要让键盘收回,这个需要用一个简单的让文本框失去第一响应者的身份来完成.或者是 ...
- iOS开发之获取系统相册ALAssetLibrary
注:当你选择看这篇博客时想必你的应用还支持iOS8一下系统,如果你的应用要求最低版本大于iOS8,建议使用PhotoKit框架,效率更高 ALAssetsLibrary包含,ALAssetsLibra ...
- iOS开发——高级技术&摇一摇功能的实现
摇一摇功能的实现 在AppStore中多样化功能越来越多的被使用了,所以今天就开始介绍一些iOS开发的比较实用,但是我们接触的比较少的功能,我们先从摇一摇功能开始 在 UIResponder中存在这么 ...
- 分分钟解决iOS开发中App启动广告的功能
前不久有朋友需要一个启动广告的功能,我说网上有挺多的,他说,看的不是很理想.想让我写一个,于是乎,抽空写了一个,代码通俗易懂,简单的封装了一下,各种事件用block回调的,有俩种样式的广告,一种是全屏 ...
- iOS开发 - Swift使用GCD实现计时器功能
前言 开发中,经常会用到定时执行网络请求.倒计时.计时器等功能,本篇文章介绍在iOS开发中,Swift怎样使用GCD实现这些功能. 执行一次 下面的代码将会在5秒后执行,且只执行一次. let tim ...
- iOS开发——UI_swift篇&UITableView实现索引功能
UITableView实现索引功能 关于UItableView的索引在平时项目中所见不多,最多的就是跟联系人有关的界面,虽然如此,但是作为一个swift开发的程序必须知道的一个技术点,所以今天 ...
- iOS开发小技巧--相机相册的正确打开方式
iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...
- iOS开发——高级技术&二维码功能的实现
二维码功能的实现 ZBarSDK,一个比较优秀的开源项目,使用起来也很简单. ZBarSDK是一个开源的SDK,可从这里下载到源码,该SDK实现了识别和读取各种条形码,包括EAN-13/UPC-A, ...
- iOS开发检测是否开启定位、是否允许消息推送等权限
1.iOS开发检测是否开启定位: 需要导入: #import <CoreLocation/CoreLocation.h> 代码如下: + (void)openLocationService ...
随机推荐
- Java线程池的实现
线程池的作用: 一个线程的周期分为:创建.运行.销毁三个阶段. 处理一个任务时,首先创建一个任务线程,然后执行任务,完了还要销毁线程.而线程只有处于运行状态的时候,才是真的在处理我们交给它的任务,这个 ...
- rails开发demo(一)搭建环境
环境 ubuntu 14.04 为了安装rails4.2 和 ruby 2.2.2,这是目前稳定的最新版本,需要先安装rvm sudo apt-get update sudo apt-get inst ...
- 二叉树 最近祖先lca + 两个结点的最小路径
http://www.acmerblog.com/distance-between-given-keys-5995.html lca在后序遍历中找, tralian算法还不会,懂了再补充 有了lca就 ...
- Servlet生命周期+工作原理
Servlet生命周期+工作原理 1.Servlet的生命周期: Servlet加载,加载,服务,销毁. 2.典型函数解释: Init():这个函数是用来初始化Servlet对象的.在 ...
- Tip和菜单的实现方式
Tip和菜单有类似的功能,即鼠标光标移上去的时候显示指定元素,鼠标光标离开的时候隐藏该元素.如下 示例1:下拉菜单(鼠标移动到“客户服务”上时出现,离开则隐藏) 示例2:水平菜单(鼠标移动到“餐饮美食 ...
- sublime学习
1:goto anything 特性 快捷键 ctrl + P @ : # 使用 2:多行游标功能 快捷键 ctrl + D ctrl + K 跳过选择 alt + F3 多选 产生 ...
- Linux shell basic3 dd wc comm chmod ls
Generating files of any size /dev/zerois a character special device, which infinitely returns the ze ...
- dw websites
http://www.kimballgroup.com/data-warehouse-business-intelligence-resources/kimball-techniques/dimens ...
- leetcode_438_Find All Anagrams in a String_哈希表_java实现
题目: Given a string s and a non-empty string p, find all the start indices of p's anagrams in s. Stri ...
- [转载]ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件
作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...