iOS - 使用进阶

时间:2022-09-24 14:53:45

1. 状态栏显示风火轮

//  ViewController.m

//  1.状态栏显示风火轮

//

//  Created by wind on 16/11/13.

//  Copyright © 2016年 wind. All rights reserved.

//

/*

功能:转太烂显示风火轮

作用:执行某个长时间动作时,提示用户耐心等待动作的执行

*/

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@

end

2. 隐藏顶部状态栏

  info.plist种操作,如下:

iOS - 使用进阶

3. 获取App的当前版本号

iOS - 使用进阶

4. 列出设备上所有字体

//实际工作中,经常需要调整界面元素的字体种类,本节课将为你输出系统提供的所有字体.

//方便你的检索和使用

//遍历设备中的所有字体

for (NSString *family in [UIFont familyNames]) {

//输出字体组的名称

NSLog(@"**********************%@",family);

//遍历字体组中所有的字体

for (NSString *font in [UIFont fontNamesForFamilyName:family]) {

//输出字体组中字体的名称

NSLog(@"\t----------------------------%@",font);

}

}

5. 对 App进行截屏

//1. 如何截屏 2.存入系统相册

//创建一个颜色对象,使用一张背景图片,作为颜色对象的内容

UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg.jpeg"]];

//将进行平铺的图案,作为根视图的背景颜色

self.view.backgroundColor = background;

//在图形上下文中,渲染当前窗口根视图的层.

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

//将上下文中的内容,转换成图像对象.

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

//关闭上下文

UIGraphicsEndImageContext();

//保存至系统相册

UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

6. 使用UIApplication打开网页

//使用应用程序单例对象,打开网页的功能

//获取应用程序单例对象,使用它的打开网址功能,打开网页.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];

7. 使用UIApplication拨打电话

//使用应用程序单例对象,拨打电话的功能

//1.创建一个字符串,注意它的前缀

NSString *string = @"tel:18860358995";

//2.转换成网址对象

NSURL *url = [NSURL URLWithString:string];

//3.获取应用程序单例对象,使用它的单例对象,使用它的打开网址功能,调出通信面板,需要真机测试

[[UIApplication sharedApplication] openURL:url];

8. 使用UIApplication发送短信

//使用应用程序单例对象, 发送短信的功能

//1. 创建一个字符串,注意它的前缀

NSString *string = @"sms:18860358995";

//2. 转换成网址对象

NSURL *url = [NSURL URLWithString:string];

[[UIApplication sharedApplication] openURL:url];

9. 邮件功能的使用

//使用应用程序单例对象, 发送邮件功能

NSString *string = @"mailto://tapinfinity@gmail.com";

NSURL *url = [NSURL URLWithString:string];

[[UIApplication sharedApplication] openURL:url];

10. 给方法添加标注

iOS - 使用进阶

11. 使用XCode的版本管理功能(SCM)

//系统的版本控制功能

//使用版本控制,可以方便地查看代码修改纪录,及恢复为之前的版本.

NSLog(@">>>>>>>>>>>>>>>>>>>>>>>>>>>Test SVN.");

//注:可以在左侧项目蓝,看到某个文件名城的右侧,有个[M]标志,表示该文件已经被编辑,但是尚未被提交 eg:ViewController.m

//1. 选择版本控制选项

//2. 选择提交代码文件选项,将该代码文件,提交给版本控制.

//3. 提交代码前,还需要给这次的版本提交,添加说明文字,作为提交日志以方便日后查看

// 点击提交按钮,提交代码后, 文件名称右侧的[M]标志,已经消失

//修改代码,例:添加一行代码

iOS - 使用进阶iOS - 使用进阶

iOS - 使用进阶

iOS - 使用进阶

12. 实现App的Settings设置

13. App图标上显示数字

//给应用程序图标,添加数字角标

[UIApplication sharedApplication].applicationIconBadgeNumber = 3;

14. 检测陀螺仪设备的状态

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//添加framework:CoreMotion

//功能:负责三种数据,加速度值,陀螺仪值,设备移动值

BOOL isGyroscopeAvailable = [self isGyroscopeAvailable];

NSLog(@">>>>>>>>>>%d",isGyroscopeAvailable);

}

-(BOOL)isGyroscopeAvailable {

//判断系统版本是否为4.0以上

#ifdef __IPHONE_4_0

//初始化管理动作对象

CMMotionManager *motionManager = [[CMMotionManager alloc] init];

//获得陀螺仪设备是否可用

BOOL gyroscopeAvailabel = motionManager.gyroAvailable;

return gyroscopeAvailabel;

//系统版本低于4.0

#else

return NO;

#endif

}

15. 检测定位设备的状态

/*

任何想要获得用户位置信息的应用,都会用到CoreLocation框架.可方便获取设备位置.

*/

//判断设备是否已经开启地理位置的服务

BOOL locationServicesEnabled = [CLLocationManager locationServicesEnabled];

//判断设备是否具备磁力感应,磁力感应可以控制地理位置的精确度

BOOL magnetometerAvailbale = [CLLocationManager headingAvailable];

NSLog(@">>>>>>>>locationServiceEnabled:%d",locationServicesEnabled);

NSLog(@">>>>>>>>locationServiceEnabled:%d",magnetometerAvailbale);

16. 检测前后相机设备的状态

//检测设备的后摄像头是否可用

BOOL cameraAvailable = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];

//检测设备的前摄像头是否可用

BOOL frontAvailable = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];

NSLog(@"后摄像头状态:%d",cameraAvailable);

NSLog(@"前摄像头状态:%d",frontAvailable);

17. 使用Quartz2D绘制基本图形

(1) 自定义QuartzView(继承UIView)

@implementation QuartzVew

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

// Drawing code

//重写父类方法

//1. 获得当前视图的上下文

CGContextRef context = UIGraphicsGetCurrentContext();

//2. 在图形上下文中,创建和设置背景填充颜色为黄色.

CGContextSetRGBFillColor(context, 1.0, 1.0, 0.0, 1.0);

//3. 使用黄色填充区域

CGContextFillRect(context, rect);

//4. 创建和设置边框颜色为黑色

CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0);

//5. 设置画笔的线条粗细

CGContextSetLineWidth(context, 2.0);

//6. 设置矩形的位置及尺寸

CGRect rect2 = CGRectMake(100, 350, 100, 30);

//7. 将矩形边框添加至上下文,作为绘制矩形的准备工作

CGContextAddRect(context, rect2);

//8. 绘制举行边框

CGContextStrokePath(context);

//9. 设置画笔的线条粗细

CGContextSetLineWidth(context, 2.0);

//10. 设置填充颜色

CGContextSetRGBFillColor(context, 1.0, 0.0, 1.0, 1.0);

//11. 创建一个字体对象

UIFont *font = [UIFont boldSystemFontOfSize:31];

NSString *text = @"Hello";

//12. 设置文字的现实位置和尺寸

CGRect rect3 = CGRectMake(100, 120, 100, 30);

//13. 将文字绘制在指定的区域内

[text drawInRect:rect3 withFont:font];

//14. 设置画笔的线条粗细

CGContextSetLineWidth(context, 5.0);

//15. 设置线条样式

CGContextSetLineCap(context, kCGLineCapButt);

//16. 设置边框的颜色

CGContextSetRGBStrokeColor(context, 1, 0, 0, 1);

//17. 创建一个坐标数组

CGPoint points[5];

//18. 设定坐标数组的内容

points[0] = CGPointMake(100, 200);

points[1] = CGPointMake(100, 300);

points[2] = CGPointMake(200, 300);

points[3] = CGPointMake(200, 200);

points[4] = CGPointMake(100, 200);

//19. 将坐标连线置入上下文

CGContextAddLines(context, points, 5);

//20. 执行绘制边框动作

CGContextStrokePath(context);

}

(2) 根视图控制器对应的类ViewDidLoad中:

//设定视图显示区域

CGRect rect = self.view.bounds;

//初始化自定义视图对象

QuartzVew *view = [[QuartzVew alloc] initWithFrame:rect];

//将视图添加至当前窗口的根视图

[self.view addSubview:view];

//////////////////////////////////////////////////////////////////////////

18. App图标名称的国际化

/*

1.点击项目名称,进入项目设置面板

2.切换简体中文

* *实现通过修改多语言环境下的配置文件,实现程序名称的国际化

*/

//////////////////////////////////////////////////////////////////////////

19. App内容文本的国际化

//通过一个宏,查找国际化资源文件中,键值标签所指向的字符串

NSString *str = NSLocalizedString(@"label", @"");

//创建一个标签对象,用老显示获得的字符串

UILabel *label = [[UILabel alloc] init];

label.frame = CGRectMake(130, 100, 250, 60);

label.text = str;

[self.view addSubview:label];

20. 计算两个日期间的差值

//计算日期间的差值

NSDate *dateA = [NSDate date];

NSDate *dateB = [[NSDate alloc] initWithTimeInterval:-60*60*24*1000 sinceDate:[NSDate date]];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSDateComponents *components = [calendar components:NSYearCalendarUnit | NSMoviesDirectory | NSDayCalendarUnit

fromDate:dateA

toDate:dateB

options:0];

NSLog(@"Different in date components: %i/%i/%i",components.day,components.month,components.year);

21. 正则表达式的使用

//检测邮箱格式的正确性

NSString *str = @"1983457078@gmail.com";

//创建一个正则表达式类,帮助您检测字符串,是否匹配正则表达式.

NSRegularExpression *regexEmail = [NSRegularExpression regularExpressionWithPattern:@"^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w{2,3}){1,3})$" options:0 error:nil];

//返回第一个匹配的结果

NSTextCheckingResult *isEmail = [regexEmail firstMatchInString:str options:0 range:NSMakeRange(0, [str length])];

//根据结果做相应的处理

if (isEmail) {

UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Perfect!" message:@"It's an email" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];

[alertview show];

}else {

UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Sorry." message:@"It's not an email" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];

[alertview show];

}

22. 本地同志的使用

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//本地通知,进行应用程序的本地同志

//创建一个本地同志对象

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

NSDate *now = [NSDate date];

//设置在当前时间的2秒后,触发本地通知

localNotification.fireDate = [now dateByAddingTimeInterval:2];

//设置重复次数

localNotification.repeatInterval = 0;

//设置时区:默认

localNotification.timeZone = [NSTimeZone defaultTimeZone];

//设置通知的提醒声音模版.

localNotification.soundName = UILocalNotificationDefaultSoundName;

//设置通知的文本内容

localNotification.alertBody = @"Hi,it's time to make a decision!";

//设置程序图标右上角显示的数字

localNotification.applicationIconBadgeNumber = 1;

//创建一个字典对象,用来传递数据

NSDictionary *infoDic = [NSDictionary dictionaryWithObject:@"infoValue"  forKey:@"infoKey"];

localNotification.userInfo = infoDic;

//开始定时执行通知,点击切换至项目代理文件.

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

//将程序右上角的数字减1

application.applicationIconBadgeNumber -= 1;

}

//新建一个代理方法,用来处理客户点击通知后的时间

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {

UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"HURRY UP" message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

[alertview show];

//获得传递来的字典对象

NSDictionary *dic = notification.userInfo;

//输出传递的内容

NSLog(@"The value of infoKey:%@",[dic objectForKey:@"infoKey"]);

//将程序图标右上角数字减1

application.applicationIconBadgeNumber -= 1;

}

23. 使用Application Loader发布应用

iOS - 使用进阶的更多相关文章

  1. iOS开发进阶

    <iOS开发进阶>基本信息作者: 唐巧 出版社:电子工业出版社ISBN:9787121247453上架时间:2014-12-26出版日期:2015 年1月开本:16开页码:268版次:1- ...

  2. iOS开发进阶&lpar;唐巧&rpar;读书笔记&lpar;一&rpar;

    如何提高iOS开发技能 1.阅读博客:https://github.com/tangqiaoboy/iOSBlogCN 40多位iOS开发博主的博客地址 2.读书:每年阅读一本高质量的iOS开发书籍 ...

  3. &lbrack;iOS UI进阶 - 6&period;1&rsqb; 核心动画CoreAnimation

    A.基本知识 1.概念 Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事半功倍,使用它需要先添加QuartzCore.framework和引入对 ...

  4. &lbrack;iOS UI进阶 - 6&period;0&rsqb; CALayer

    A.基本知识 1.需要掌握的 CALayer的基本属性 CALayer和UIView的关系 position和anchorPoint的作用   2.概念 在iOS中,你能看得见摸得着的东西基本上都是U ...

  5. &lbrack;iOS UI进阶 - 3&period;1&rsqb; 触摸事件的传递

    A.事件的产生和传递 发生触摸事件后,系统会将该事件加入到一个由UIApplication管理的事件队列中UIApplication会从事件队列中取出最前面的事件,并将事件分发下去以便处理,通常,先发 ...

  6. &lbrack;iOS UI进阶 - 3&period;0&rsqb; 触摸事件的基本处理

    A.需要掌握和练习的 1.介绍事件类型2.通过按钮的事件处理引出view的事件处理3.响应者对象 --> UIResponder --> UIView4.view的拖拽* 实现触摸方法,打 ...

  7. &lbrack;iOS UI进阶 - 2&period;3&rsqb; 彩票Demo v1&period;3

    A.需求 真机调试 "关于”模块 存储开关状态 打电话.发短信 应用评分 打开其他应用 cell 在iOS6 和 iOS7的适配 block的循环引用 屏幕适配 code source:   ...

  8. &lbrack;iOS UI进阶 - 2&period;0&rsqb; 彩票Demo v1&period;0

    A.需求 1.模仿“网易彩票”做出有5个导航页面和相应功能的Demo 2.v1.0 版本搭建基本框架   code source:https://github.com/hellovoidworld/H ...

  9. &lbrack;iOS UI进阶 - 0&rsqb; Quiartz2D

    A.简介 1. 需要掌握的 drawRect:方法的使用 常见图形的绘制:线条.多边形.圆 绘图状态的设置:文字颜色.线宽等 图形上下文状态的保存与恢复 图形上下文栈 1.基本图形绘制* 线段(线宽. ...

  10. iOS开发进阶-实现多线程的3种方法

    相关文章链接: 1.多线程简介 2.实现多线程的3种方法 ......待续 前言 在多线程简介中,我已经说明过了,为了提高界面的流畅度以及用户体验.我们务必要把耗时的操作放到别的线程中去执行,千万不要 ...

随机推荐

  1. javascript 中 Promise的使用

    有点经验的js前端都知道  ajax异步函数里面的结果不会立即返回,如果你想在一个异步函数得到某个结果后去执行一个语句怎么做? if ( 异步函数 ) { 语句 }  可能很多人都踩过这样坑,这个时候 ...

  2. WCF服务的异常消息

    原创地址:http://www.cnblogs.com/jfzhu/p/4055024.html 转载请注明出处 WCF Service发生异常的时候,客户端一般只能看见这样一个错误:“The ser ...

  3. java web 学习 --第十一天(Java三级考试)

    第十天的学习内容:http://www.cnblogs.com/tobecrazy/p/3473954.html Servlet理论知识: 1.servlet 生成class位置 tomcat编译后生 ...

  4. &lbrack;置顶&rsqb; Android源码分析-点击事件派发机制

    转载请注明出处:http://blog.csdn.net/singwhatiwanna/article/details/17339857 概述 一直想写篇关于Android事件派发机制的文章,却一直没 ...

  5. 模仿 app

    原文链接:http://www.jianshu.com/p/a634b66cb180 前言 作为一个IOS程序员,闲的时候也想自己做一个app练练手,又苦于没有UI设计,也没有好的idea,所以只能先 ...

  6. WebService调用&lpar;基于KSOAP2&rpar;

    public static boolean getData(String param) { //WebService服务器地址 String SERVICE_URL = "http://22 ...

  7. cookie猜数字游戏(下)------------以及cookie使用的不安全之处

    1.通过cookie可以解决上篇中多个用户对数据的修改,每个COOKIE保存不同用户的数据 <?php if(empty($_COOKIE['num'])||empty($_GET['num'] ...

  8. JeeSite框架中httpSession&period;invalidate&lpar;&rpar;&semi;无效

    想要实现一个功能:同一个用户在两个不同的浏览器中登录,后面的踢掉之前的登录. 本来的思路是在httpSession监听器中进行判断.但是在使用httpSession.invalidate();销毁Se ...

  9. 2017-2018-2 《网络对抗技术》 20155310 第二周 Exp1 PC平台逆向破解&lpar;5&rpar;M

    2017-2018-2 <网络对抗技术> 20155310 第二周 Exp1 PC平台逆向破解(5)M 一.实践目标 1.1实践介绍 本次实践的对象是一个名为pwn1的linux可执行文件 ...

  10. Falsk项目cookie中的 csrf&lowbar;token 和表单中的 csrf&lowbar;token实现

    Flask中请求体的请求开启CSRF保护可以按以下配置 from flask_wtf.csrf import CSRFProtect app.config.from_object(Config) CS ...