OC代码片段
2018-04-10 本文已影响9人
Hamiltonian
//打印指针的内存地址
NSLog(@"%x",self.redView);
//打印指针指向对象的内存地址
NSLog(@"%p",self.redView);
//打印对象
NSLog(@"%@",self.redView);
//从数组中取值,要注意数组越界
if (leftLanguageIndex + 1 > availableVoices.count) {
leftLanguageIndex = availableVoices.count - 1;
}
if (rightLanguageIndex + 1 > availableVoices.count) {
rightLanguageIndex = availableVoices.count - 1;
}
//代理协议要遵守<NSObject>
@protocol secViewControllerDelegate <NSObject>
//实现代理协议要先判断delegate是否能够相应对应的方法!!
//不判断会崩溃!!!
if ([self.delegate respondsToSelector:@selector(returnString:)]) {
[self.delegate returnString:@"dfs"];
}
//监听通知中心,由于APPDelegate只会调用一次,所以写在这里最好
[self setUpNotification];
//通过动画CAKeyFrameAnimation来写闪烁效果
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
animation.values=@[@1,@0,@1];
animation.repeatCount=MAXFLOAT;
animation.duration = 2;
animation.removedOnCompletion = NO;
[button.layer addAnimation:animation forKey:nil];
//隐藏导航栏分割线
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
//设置导航栏背景颜色
[UINavigationBar appearance].barTintColor=kNavBackColor;
//设置导航栏标题 大小 颜色
NSDictionary * navigationTitleAttDic = @{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:UIColorFromRGB(74,74,74)};
[[UINavigationBar appearance] setTitleTextAttributes:navigationTitleAttDic];
@try{
NSArray *array = [NSArray new];
NSLog(@"%@",array[0]);
}
@catch(NSException *exception){
NSLog(@"%@",exception);
}
@finally{
}
子类重写基类的方法,要先调用下父类的方法