[iOS UI进阶 - 2.3] 彩票Demo v1.3
- 真机调试
- "关于”模块
- 存储开关状态
- 打电话、发短信
- 应用评分
- 打开其他应用
- cell 在iOS6 和 iOS7的适配
- block的循环引用
- 屏幕适配
NSURL *url = [NSURL URLWithString:@"tel://10086"];
[[UIApplication sharedApplication] openURL:url];
缺点
电话打完后,不会自动回到原应用,直接停留在通话记录界面
NSURL *url = [NSURL URLWithString:@"telprompt://10086"];
[[UIApplication sharedApplication] openURL:url];
缺点
因为是私有API,所以可能不会被审核通过
if (_webView == nil) {
_webView = [[UIWebView alloc] initWithFrame:CGRectZero];
}
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10010"]]];
需要注意的是:这个webView千万不要添加到界面上来,不然会挡住其他界面
NSURL *url = [NSURL URLWithString:@"sms://10086"];
[[UIApplication sharedApplication] openURL:url];
包含主头文件
#import <MessageUI/MessageUI.h>
显示发短信的控制器
MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init];
// 设置短信内容
vc.body = @"吃饭了没?";
// 设置收件人列表
vc.recipients = @[@"", @""];
// 设置代理(这里使用block封装,由于强指针持有self,会有内存泄露)
vc.messageComposeDelegate = self; // 显示控制器
[self presentViewController:vc animated:YES completion:nil];
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
// 关闭短信界面
[controller dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultCancelled) {
NSLog(@"取消发送");
} else if (result == MessageComposeResultSent) {
NSLog(@"已经发出");
} else {
NSLog(@"发送失败");
}
}
NSURL *url = [NSURL URLWithString:@"mailto://10010@qq.com"];
[[UIApplication sharedApplication] openURL:url];
// 方法2:使用控制器
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; // 发送主题
[mailController setSubject:@"重要作战会议"]; // 邮件内容
[mailController setMessageBody:@"就是那个...该吃饭了吧" isHTML:NO]; // 收件人
[mailController setToRecipients:@[@"hellovoidworld@163.com"]]; // 抄送人
[mailController setCcRecipients:@[@"hellovoidworld@163.com"]]; // 密送人
[mailController setBccRecipients:@[@"hellovoidworld@163.com"]]; // 附件
UIImage *image = [UIImage imageNamed:@"LoginScreen"];
NSData *data = UIImagePNGRepresentation(image);
[mailController addAttachmentData:data mimeType:@"image/png" fileName:@"attach.png"]; // 代理
mailController.mailComposeDelegate = shareController; // 弹出mail控制器
[shareController presentViewController:mailController animated:YES completion:nil];
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
// 关闭邮件界面
[controller dismissViewControllerAnimated:YES completion:nil]; if (result == MFMailComposeResultCancelled) {
NSLog(@"取消发送");
} else if (result == MFMailComposeResultSent) {
NSLog(@"已经发出");
} else {
NSLog(@"发送失败");
}
}
只需要告诉UIWebView文件的URL即可
至于打开一个远程的共享资源,比如http协议的,也可以调用系统自带的Safari浏览器:
NSURL *url = [NSURL URLWithString:@”http://www.baidu.com"];
[[UIApplication sharedApplication] openURL:url];
NSURL *url = [NSURL URLWithString:@"hvw://com.ios.app"];
[[UIApplication sharedApplication] openURL:url];
如何跳转到AppStore,并且展示自己的应用
方法1
NSString *appid = @"";
NSString *str = [NSString stringWithFormat:
@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%@", appid];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
方法2
NSString *str = [NSString stringWithFormat:
@"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
登录开发者主页
生成cer证书:cer是一个跟电脑相关联的证书文件,让电脑具备真机调试的功能
添加App ID:调试哪些app?
注册真机设备:哪台设备需要做真机调试?
生成MobileProvision文件:结合2、3、4生成一个手机规定文件
导入cer、MobileProvision文件
最终会得到2个文件
Cer文件:让电脑具备真机调试的功能
MobileProvision文件:哪台设备、哪些app、哪台电脑需要做真机调试?
- 新浪微博分享
- 短信分享
- 邮件分享

//
// HVWShareViewController.m
// HelloLottery
//
// Created by hellovoidworld on 15/1/9.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWShareViewController.h"
#import "HVWArrowSettingItem.h"
#import "HVWSettingGroup.h"
#import <MessageUI/MessageUI.h> @interface HVWShareViewController () <MFMessageComposeViewControllerDelegate, MFMailComposeViewControllerDelegate> @end @implementation HVWShareViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. // 配置数据
HVWSettingItem *weiboShare = [HVWArrowSettingItem itemWithIcon:@"WeiboSina" title:@"新浪微博分享"];
HVWSettingItem *smsShare = [HVWArrowSettingItem itemWithIcon:@"SmsShare" title:@"短信分享"]; // 为了避免block内持有本控制器,导致内存泄露,先声明一个弱指针
__weak HVWShareViewController *shareController = self; smsShare.runningBlock = ^ {
// 方法1:只能打开短信窗口,不能指定内容
// NSURL *smsURL = [NSURL URLWithString:@"sms://10086"];
// [[UIApplication sharedApplication] openURL:smsURL]; // 方法2:
//获取短信发送控制器
if (![MFMessageComposeViewController canSendText]) return; MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init]; // 短信内容
messageController.body = @"吃饭了没有?"; // 收件人
messageController.recipients = @[@""]; // 设置代理,特别注意代理是messageComposeDelegate,不是delegate
messageController.messageComposeDelegate = shareController; // 显示控制器
[shareController presentViewController:messageController animated:YES completion:nil];
}; HVWSettingItem *mailShare = [HVWArrowSettingItem itemWithIcon:@"MailShare" title:@"邮件分享"];
mailShare.runningBlock = ^ {
// 方法1:直接调用
// NSURL *mailURL = [NSURL URLWithString:@"mailto://hellovoidworld@163.com"];
// [[UIApplication sharedApplication] openURL:mailURL]; // 方法2:使用控制器
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; // 发送主题
[mailController setSubject:@"重要作战会议"]; // 邮件内容
[mailController setMessageBody:@"就是那个...该吃饭了吧" isHTML:NO]; // 收件人
[mailController setToRecipients:@[@"hellovoidworld@163.com"]]; // 抄送人
[mailController setCcRecipients:@[@"hellovoidworld@163.com"]]; // 密送人
[mailController setBccRecipients:@[@"hellovoidworld@163.com"]]; // 附件
UIImage *image = [UIImage imageNamed:@"LoginScreen"];
NSData *data = UIImagePNGRepresentation(image);
[mailController addAttachmentData:data mimeType:@"image/png" fileName:@"attach.png"]; // 代理
mailController.mailComposeDelegate = shareController; // 弹出mail控制器
[shareController presentViewController:mailController animated:YES completion:nil]; }; HVWSettingGroup *group = [[HVWSettingGroup alloc] init];
group.items = @[weiboShare, smsShare, mailShare];
[self.data addObject:group];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} #pragma mark - MFMessageComposeViewControllerDelegate 代理方法
/** 关闭信息后 */
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
// 关闭信息窗口
[controller dismissViewControllerAnimated:YES completion:nil]; // 检测发送情况
if (MessageComposeResultSent == result) {
NSLog(@"成功发送!");
} else if (MessageComposeResultFailed == result) {
NSLog(@"发送失败!");
} else if (MessageComposeResultCancelled == result) {
NSLog(@"取消发送!");
} else {
NSLog(@"发生错误!");
}
} /** 关闭邮件后 */
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[controller dismissViewControllerAnimated:YES completion:nil];
} @end



//
// HVWAboutViewController.m
// HelloLottery
//
// Created by hellovoidworld on 15/1/8.
// Copyright (c) 2015年 hellovoidworld. All rights reserved.
// #import "HVWAboutViewController.h"
#import "HVWArrowSettingItem.h"
#import "HVWSettingGroup.h" @interface HVWAboutViewController () @end @implementation HVWAboutViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. // 准备一个webView
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
[self.view addSubview:webView]; // 配置item和group
HVWSettingItem *gradeSupport = [HVWArrowSettingItem itemWithTitle:@"评分支持"]; // 跳转到app store进行应用评分
gradeSupport.runningBlock = ^ {
// 其实这是网易新闻的app id
NSString *appid = @"";
NSString *appStoreAddr = [NSString stringWithFormat:@"http://itunes.apple.com/app/id%@?mt=8", appid];
NSURL *appStoreURL = [NSURL URLWithString:appStoreAddr];
[[UIApplication sharedApplication] openURL:appStoreURL];
}; HVWSettingItem *servicePhone = [HVWArrowSettingItem itemWithTitle:@"客服电话"];
NSString *phoneNumber = @"020-83568090";
servicePhone.subTitle = phoneNumber; servicePhone.runningBlock = ^{
NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phoneNumber]];
[webView loadRequest:[NSURLRequest requestWithURL:phoneURL]];
}; HVWSettingGroup *group = [[HVWSettingGroup alloc] init];
group.items = @[gradeSupport, servicePhone];
[self.data addObject:group]; // header
// 配置header view
UINib *nib = [UINib nibWithNibName:@"HVWAboutHeader" bundle:[NSBundle mainBundle]];
UIView *view = [[nib instantiateWithOwner:nil options:nil] lastObject];
self.tableView.tableHeaderView = view;
self.tableView.tableHeaderView.frame = view.bounds;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

/** 创建“开关”类型的cell */
- (UISwitch *)switchView {
if (nil == _switchView) {
_switchView = [[UISwitch alloc] init]; // 监听开关
[_switchView addTarget:self action:@selector(switchChange) forControlEvents:UIControlEventValueChanged];
}
return _switchView;
} /** 开关变化事件
* 存储开关状态到preferences
*/
- (void) switchChange {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// 使用cell的title作为key,开关状态作为value
[defaults setBool:self.switchView.isOn forKey:self.item.title];
// 立即存储
[defaults synchronize];
} /** 读取开关状态 */
- (BOOL) readSwitchStatus {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
return [defaults boolForKey:self.item.title];
}


- 打开应用URL
- 下载应用URL

#pragma mark <UICollectionViewDelegate>
/** 选择事件 */
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
HVWProduct *product = self.products[indexPath.item]; NSURL *appUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@", product.urlSchema, product.urlId]];
NSURL *appStoreUrl = [NSURL URLWithString:product.appStoreUrl]; UIApplication *application = [UIApplication sharedApplication];
// 先判断是否存在此app
if ([application canOpenURL:appUrl]) {
// 打开app
[application openURL:appUrl];
} else {
// 跳转到app store下载app
[application openURL:appStoreUrl];
}
}
- 重写cell的setFrame方法
- 在iOS6及以下系统修改cell的位置尺寸,适配iOS7
- iOS6中,cell中右部分的子控件不属于contentView,所以contentView的宽度是不定的
- 每组的最后一行不需要分隔线


[iOS UI进阶 - 2.3] 彩票Demo v1.3的更多相关文章
- [iOS UI进阶 - 2.4] 彩票Demo v1.4 转盘动画
A.需求 幸运广场界面中有一个幸运转盘,平时能够自动缓缓转动 能够选择星座 点击“开始选号”开速旋转转盘,旋转一定周数 转盘转动速度节奏:开始-慢-块-慢-结束 设置其余的背景和按钮 code s ...
- [iOS UI进阶 - 2.0] 彩票Demo v1.0
A.需求 1.模仿“网易彩票”做出有5个导航页面和相应功能的Demo 2.v1.0 版本搭建基本框架 code source:https://github.com/hellovoidworld/H ...
- [iOS UI进阶 - 2.1] 彩票Demo v1.1
A.需求 1.优化项目设置 2.自定义导航栏标题按钮 3.多版本处理 4.iOS6和iOS7的适配 5.设置按钮背景 6.设置值UIBarButtonItem样式 code source: htt ...
- [iOS UI进阶 - 2.2] 彩票Demo v1.2 UICollectionView基本
A.需要掌握的 设计.实现设置界面 cell的封装 UICollectionView的使用 自定义UICollectionView 抽取控制器父类 "帮助"功能 code sour ...
- [iOS UI进阶 - 5.0] 手势解锁Demo
A.需求 1.九宫格手势解锁 2.使用了绘图和手势事件 code source: https://github.com/hellovoidworld/GestureUnlockDemo B ...
- [iOS UI进阶 - 4.0] 涂鸦app Demo
A.需求 1.超简易画图,只有一种画笔 2.清屏功能 3.回退功能 4.保存功能 5.使用了cocos2D code source: https://github.com/hellovoidwor ...
- [iOS UI进阶 - 0] Quiartz2D
A.简介 1. 需要掌握的 drawRect:方法的使用 常见图形的绘制:线条.多边形.圆 绘图状态的设置:文字颜色.线宽等 图形上下文状态的保存与恢复 图形上下文栈 1.基本图形绘制* 线段(线宽. ...
- iOS UI进阶-1.0 Quartz2D
概述 Quartz 2D是一个二维绘图引擎,同时支持iOS和Mac系统.Quartz 2D能完成的工作: 绘制图形 : 线条\三角形\矩形\圆\弧等 绘制文字 绘制\生成图片(图像) 读取\生成PDF ...
- UI进阶之--网易彩票手写plist文件,动态创建控制器与tableViewcell
点击右上角设置按钮 点击按钮后发生的事件:1. 控制器的跳转,进入新的控制器.view, 2. 跳转的时候对将要跳转的目标控制的子控件进行了布局.---通过手写plist文件的方式加载 为按钮注册单击 ...
随机推荐
- noi2002银河英雄传说(并查集)
首先表示对C++读入读出问题复杂程度的敬畏,看了好多没讲明白的,本题用cin竟然过不了评测,搞scanf的读入搞了好久.... 本题确实是一道经典的并查集题型,不多讲,拿来练练手用的(其中经历很惨) ...
- apache开源项目 -- tomee
Apache TomEE,发音是“Tommy”,是一个经Apache.JavaEE6.Web框架认证的适配器,其在Tomcat服务器中是最强大的.Apache TomEE是由香草项目(简化常见编程任务 ...
- fmri当前相关软件工具整理
1.spm; 2.afni; 3.fsl; 4.drtools; 5.prtools; 6.phycaa+; 7.cca-fmri;
- POI读取Word与Excel
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; ...
- delphi 对话框初始地址InitialDir
我的电脑:SaveDialog1.InitialDir := '::{20D04FE0-3AEA-1069-A2D8-08002B30309D}';// My Computer {20D04FE0-3 ...
- 字符集编码Unicode ,gb2312 cp936
这是一篇程序员写给程序员的趣味读物.所谓趣味是指可以比较轻松地了解一些原来不清楚的概念,增进知识,类似于打RPG游戏的升级.整理这篇文章的动机是两个问题: 问题一:使用Windows记事本的“另存为” ...
- FastDFS总结
前言 FastDFS主要解决互联网中小文件存储存储问题,例如图片,短视频,提供上传和下载功能,轻量级的设计,结构非常简单,主要包含三个角色客户端,Tracer服务,Storage服务.Tracer服务 ...
- linux命令——磁盘管理cd
Linux cd 命令可以说是Linux中最基本的命令语句,其他的命令语句要进行操作,都是建立在使用 cd 命令上的. cd指令可让用户在不同的目录间切换,但该用户必须拥有足够的权限进入目的目录. 1 ...
- lightoj 1022
直接算即可,特别要注意精度 #include<cstdio> #include<cmath> int main(){ int t, CASE(0); double r; sca ...
- 为移动Web应用创建快速响应按钮
英文原文出自 Google Deveploers<Creating Fast Buttons for Mobile Web Applications>,由XiaoYi_HD翻译,并首发于 ...