源码推荐(9.30):iOS 9 新特性的代码示例,Crash捕捉 崩溃捕捉
iOS 9 新特性的代码示例。使用 Xcode 7 编译。
内容包括自定义地图、文本检测、新图片滤镜、CASpringAnimation、UIStackView、省电模式、新字体,等等。

Crash捕捉,崩溃捕捉(作者:LYoung)
|
1
2
3
4
5
6
7
8
9
10
11
12
|
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//注册消息处理函数的处理方法,处理崩溃信息,写入本地 NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
return
YES; }
判断是否存在Crash日志
CrashManager *crashManager = [CrashManager defaultManager];
if
([crashManager isCrashLog]) {
//Crash日志
}
如果存在,打印Crash日志
NSString *crashString = [crashManager crashLogContent];
//Crash日志内容
NSLog(@
"crashString = %@"
,crashString);
//
清除Crash日志
[crashManager clearCrashLog];
//清除Crash日志
|
测试环境:Xcode 6.2,iOS 6.0 以上
简单的Tab页面
测试环境:Xcode 6.2

1->
|
1
2
3
4
|
//create childViews
[self createChildViews];
//load data
[self loadDataFromPlistFile];
|
2->
|
1
2
3
4
5
6
7
8
|
//create head that contains show&hide buttons and right button
[self createHeadView];
//create content index view
[self createContentIndexView];
//create content view
[self createContentView];
//create other views
[self createOtherViews];
|
测试环境:Xcode 6.2,iOS 6.0 以上

NSString *coreTextString = @"CoreText[/爱心]框架是基于 iOS 3.2+ 和 OSX 10.5+ [/握手]的一种能够对文本格式和文本布局进行精细控制的文本引擎。它良好的结合了 UIKit 和 Core Graphics/Quartz:UIKit 的 UILabel允许你通过在 IB 中简单的拖曳添加文本,[/大兵]但你不能改变文本的颜色和其中的单词。[/强]";
|
1
2
3
4
5
6
7
8
9
|
CGFloat coreLabelX = 10;
CGFloat maxW = self.view.frame.size.width - 2*coreLabelX;
CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
UILabel * coreLabel= [[UILabel alloc] init];
coreLabel.textColor = [UIColor blackColor];
coreLabel.numberOfLines = 0;
coreLabel.font = TextFont;
[self.view addSubview:coreLabel];
coreLabel.attributedText = [NSMutableAttributedString stringWithText:coreTextString];
|
计算富文本高度
|
1
2
|
CGSize textSize = [coreTextString sizeWithFont:TextFont maxSize:maxSize];
coreLabel.frame = (CGRect){{coreLabelX, 0}, textSize};
|
测试环境:Xcode 6.2,iOS 6.0 以上

本文介绍iOS9的新特性代码示例,包括自定义地图、文本检测等功能,并演示如何使用Xcode7进行Crash捕捉及日志处理。
281

被折叠的 条评论
为什么被折叠?



