iOS特别技能点总结

修改状态栏颜色

1.在 info.plist 添加 View controller-based status bar appearance 并设置为 NO(白色),YES(黑色), 如果为NO,并在 Appdelegate 里面添加

[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
则可设置为白色。

2.在有 navigationbar 的时候需要 添加方法 :

- (UIStatusBarStyle)preferredStatusBarStyle {

return UIStatusBarStyleLightContent;
} 

并且在 viewDidload 中添加:self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

这样可以设置为白色

修改 Bar Button Item 的颜色

如果要修改 Right Bar Button Items 的颜色,需要在 Bar Button Item 里面修改它的 Tint 的颜色。因为自定义右按钮Right Bar Button Items 有两个图层:Bar Button Item 和 View。

警告:Plain style unsupported in a Navigation item

解决方法: 将 plain 设置成:Bordered 。

怎样设置UITableView的cell之间的距离?

分为两种情况:

1. 分组表格    - 每段一个cell设置表头的高度 
2. 非分组表格  - 将tableViewCell的背景色,contentView的背景色设置为透明,在contentView中添加一个UIImageView做为背景,使UIImageView的高度小于cell的高度,这样创建出的tableView就可以使每个cell之间看起来有一定间隔。

performSegueWithIdentifier produce no segue with identifier error

解决方法:先检查要跳转的界面和目的界面的表格的协议(delegate和datasource)是否有代理。然后检查是否给控制器添加了类。

1.在 ios 中如果遇到添加的图片没有显示出来,可以先检查图片的名称是否正确,
然后检查图片的格式是否是 PNG 格式,最后检查是否已经添加到工程当中了。

2.在tableView 中 cell 的跳转,需要使用控制器间的跳转。

3.异常:Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b02120’

解决方法:检测视图控制器是否绑定了具体的类。

4.this class is not key value coding-compliant for the key XXX错误的解决方法

解决方法:在设置IBAction和IBOutlet时有多余的连线,按下ctrl键检查控件的连接将多余的连续删除后程序正常运行。

5.this class is not key value coding-compliant for the key leftTitle.

解决方法: 因为sb 或者 xib 中的控件链接的属性有些没有出现在页面绑定的控制器上,造成引用上的健值错误。

6.OC之OBJC2_UNAVAILABLE

意即在OBJC2.0中,这些东西将被删除。

去除 tableView 的 sectionView 的粘性

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

   CGFloat sectionHeaderHeight = 45;
   if (scrollView.contentOffset.y <= sectionHeaderHeight&&scrollView.contentOffset.y >= 0) {

       scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
   }
   else if (scrollView.contentOffset.y >= sectionHeaderHeight) {

       scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
   }
}

修改 textField 的 placeholder 的字体颜色,大小

[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];  

[textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@"_placeholderLabel.font"];