1 arc mrc 互相包含
如果你的项目使用的非 ARC 模式,则为 ARC 模式的代码文件加入 -fobjc-arc 标签。
如果你的项目使用的是 ARC 模式,则为非 ARC 模式的代码文件加入 -fno-objc-arc 标签。
2、iOS-NSDateFormatter 格式说明:
G: 公元时代,例如AD公元
yy: 年的后2位
yyyy: 完整年
MM: 月,显示为1-12
MMM: 月,显示为英文月份简写,如 Jan
MMMM: 月,显示为英文月份全称,如 Janualy
dd: 日,2位数表示,如02
d: 日,1-2位显示,如 2
EEE: 简写星期几,如Sun
EEEE: 全写星期几,如Sunday
aa: 上下午,AM/PM
H: 时,24小时制,0-23
K:时,12小时制,0-11
m: 分,1-2位
mm: 分,2位
s: 秒,1-2位
ss: 秒,2位
S: 毫秒
常用日期结构:
yyyy-MM-dd HH:mm:ss.SSS
yyyy-MM-dd HH:mm:ss
yyyy-MM-dd
MM dd yyyy
3 nslog nsstring方式输出 point rect size
NSLog(@"point: %@", NSStringFromCGPoint(point));
NSLog(@"size: %@", NSStringFromCGSize(size));
NSLog(@"rect: %@", NSStringFromCGRect(rect));
4 实例和属性区别
一般属性给外部调用的 实例是自己类用的
实例默认是保护的 就是你的子类和你可以用 其他类不可以用
5 倒计时函数
- (IBAction)sendCaptchaAction:(id)sender {
UIButton * btn = (UIButton*)sender;
[btn setEnabled:NO];
__block int timeout=60; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(_timer, ^{
if(timeout<=0){ //倒计时结束,关闭
dispatch_source_cancel(_timer);
dispatch_release(_timer);
dispatch_async(dispatch_get_main_queue(), ^{
[btn setEnabled:YES];
[btn setTitle:@"发送验证码" forState:UIControlStateNormal];
// [btn setTitle:[NSString stringWithFormat:@"重发倒数%d秒", timeout] forState:UIControlStateNormal];
});
}else{
// int minutes = timeout / 60;
// int seconds = timeout % 60;
// NSString *strTime = [NSString stringWithFormat:@"%d分%.2d秒后重新获取验证码",minutes, seconds];
dispatch_async(dispatch_get_main_queue(), ^{
[btn setTitle:[NSString stringWithFormat:@"重发倒数%d秒", timeout] forState:UIControlStateNormal];
});
timeout--;
}
});
dispatch_resume(_timer);
}
6 16进制 转 uicolor
[super getColor:@"fbf0ee"];
- (UIColor *)getColor:(NSString *)hexColor
{
unsigned int red,green,blue;
NSRange range;
range.length = 2;
range.location = 0;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];
range.location = 2;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];
range.location = 4;
[[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];
return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green / 255.0f) blue:(float)(blue / 255.0f) alpha:1.0f];
}
7 iOS 7 之前navigation bar 阴影去掉
解决方案 1:
[self.navigationController.navigationBar.layer setMasksToBounds:YES]; // 剪切掉多余的背景
解决方案 2:
self.navigationController.navigationBar.clipsToBounds = YES;
设置 navigationbartitle 属性
NSDictionary * tabBarTitleDic = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,[UIColor clearColor], UITextAttributeTextShadowColor, nil];
self.navigationController.navigationBar setTitleTextAttributes:tabBarTitleDic];
9 生成随机字符串
-(NSString *)randomCreatCheckCode
{
NSString * sourceStr = @"0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ";
NSString * destStr = [[NSString alloc]init];
NSLog(@"sourceStr count %d", [sourceStr length]);
for (int strNum = 0; strNum<10; strNum++) {
int value = arc4random()%[sourceStr length];
NSString * tempStr = [sourceStr substringWithRange:NSMakeRange(value,1)];
destStr = [destStr stringByAppendingString:tempStr];
}
NSLog(@"destStr %@", destStr);
return destStr;
}
10 运算符优先级
算术运算符 > 关系运算符 > 逻辑运算符(异或:同0异1) > 赋值运算符
11 iOS 7 适配
- (void)viewDidLoad
{
[super viewDidLoad];
// // Keeps tab bar below navigation bar on iOS 7.0+
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout = UIRectEdgeNone;
self.navigationController.navigationBar.translucent = NO;
self.extendedLayoutIncludesOpaqueBars = YES;
}
}