一、 备注
1 、\\ , \** …. *\
2、#pragma mark
3、#warning
二、 NSStirng
1、截取一个路径中最后一层文件,http://a/b/123/abc.txt ---> abc.txt
lastPathComponent
2、截取字符串中指定位置字符
NSString * word = [text substringWithRange:NSMakeRange(i, 1)] ;
instancetype
1、instancetype在类型表示上,跟id一样,可以表示任何对象类型
2、instancetype只能用在返回值类型上,不能像id一样用在参数类型上
3、instancetype比id多一个好处:编译器会检测instancetype的真实类型
三、 KVC
1、字典转模型
1、[self setValuesForKeysWithDictionary:dict];
保证模型中的属性名与字典中的属性名保持一致,并且顺序也一致
2、self.name = dict[@"name"] ;
self.age = dict[@"age"] ;
四、 状态栏
1、改变状态框的颜色
- (UIStatusBarStyle) preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
2、去掉状态框
1、在控制器中设置 — 只对当前控制器内的页面有效
- (BOOL) prefersStatusBarHidden {
return YES ;
}
2、JAppDelegate.m 文件设置 — 对启动后的程序所有界面起作用,不包括欢迎界面
application.statusBarHidden = NO ;
3、在项目配置中修改 — 从项目以启动开始生效,包括欢迎界面
General —> Deployment Info —>
3、通过apperarance控制 ,所有的页面都会改变
1、在Info.plist文件中添加由appearance控制器控制
View controller-based status bar appearance —— NO
2、LJAppDelegate.m 文件设置状态栏的样式
application.statusBarStyle = UIStatusBarStyleLightContent;
五、 计算字体尺寸
具体计算方法,已保存到分类中
// 使用宏定义字体
#define MJNameFont [UIFont systemFontOfSize:14]
CGSize nameSize = [self sizeWithText:self.status.name font:LJNameFont maxSize: CGSizeMake(MAXFLOAT, MAXFLOAT)] ;
六、 屏幕
1、屏幕的宽度
//UIScreen:设备屏幕 mainScreen:主屏幕
CGFloat screenW = [UIScreen mainScreen].bounds.size.width ;
2、设置window窗口背景色,默认为黑色
self.view.window.backgroundColor = self.tableView.backgroundColor ;
七、 Keyboard
1、当点击键盘发送按钮时触发
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
NSString * text = textField.text // 为文本框的内容
return YES ;
}
2、退出键盘
[self.view endEditing: YES] ;
3、键盘的参数 , note中有键盘移动的所有数据信息
- (void)keyboardWillChangeFrame: (NSNotification *) note {
// 获取键盘移动时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue] ;
// 获取键盘移动结束后的位置
CGRect keyBoardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue] ;
}
八、 NSDate
NSDate * now = [NSDate date] ; // 获取当前时间
NSDateFormatter * form = [[NSDateFormatter alloc] init] ;
form.dateFormat = @"HH.mm" ; // 指定时间显示格式
NSStirng * time = [form stringFromDate:now] ;
九、 显示动画效果
[UIView animateWithDuration:0.5 animations:^{ // 0.5s后执行
label.alpha = 0.5 ; // 要执行的方法
}completion:^(BOOL finished) { // 执行结束后要做的动作
[UIView animateWithDuration:0.5 animations:^{ // 可以继续嵌套一个动画效果
label.alpha = 0.0 ;
}completion:^(BOOL finished) {
[label removeFromSuperview] ;
}];
}];
十、 读取JSON文件
NSString * path = [[NSBundle mainBundle] pathForResource:@"help.json" ofType:nil] ;
// 转换成二进制文件
NSData * data = [NSData dataWithContentsOfFile:path] ;
// 存储到数组中
NSArray * dictArray = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error:nil] ;
十一、 UIKit
在UIKit中,坐标系的原点(0,0)在左上角,x值向右正向延伸,y值向下正向延伸
frame\center\bounds
1、frame:能修改位置和尺寸
2、center:能修改位置
3、bounds:能修改尺寸(x\y一般都是0)
十二、 真机调试
打电话、发邮件、分享、评分 已经记录到分类中
十三、 NSBundle
一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹,利用mainBundle就可以访问软件资源包中的任何资源
模拟器应用程序的安装路径
/Users/aplle/资源库/Application Support/iPhone Simulator/7.1/Applications
NSBundle * bundle = [NSBundle mainBundle] ; // 获取设备的根文件夹
IOS6 去掉图标玻璃效果