iOS 导航条小结

1、在创建控制器的时候,只有调用viewController.view (eg:viewControllera.view.backgroundColor = [UIColor redColor])。就会立即调用控制器生命周期方法的loadView,然后就调用viewDidLoad。然后返回到viewController.view这个方法的调用的地方。当控制器被push的时候,才会调用viewWillAppear和viewDidAppear。如果在创建控制器的时候没有调用viewController.view。则控制器的生命周期方法是在push的时候按顺序开始调用。

2、从iOS7开始,view的frame是从屏幕的左上角开始算的。所以状态栏也是在view上。

3、设置导航条的背景颜色

self.navigationController.navigationBar.barTintColor = [UIColor redColor];// 要用barTintColor属性才有效。

 4、导航条的  [[UINavigationBar appearance] setTranslucent:YES];属性。如果为YES,则view上的控件的y值要以屏幕的最顶部为标准开始计算。如果设置为NO,则控件的y值是从导航条的底部开始计算。

5、在当前类中设置当前导航条的title字体大小和颜色。

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor redColor],NSFontAttributeName : [UIFont systemFontOfSize:15]};

6、设置项目中全部的导航条的title字体大小和颜色。

NSDictionary *attributes = @{NSForegroundColorAttributeName:UIColorFromRGB(kBlueColor)};
    
[[UINavigationBar appearance] setTitleTextAttributes:attributes];

7、设置导航条的左右barButton 的tintColor

self.navigationItem.leftBarButtonItem.tintColor = UIColorFromRGB(kBlueColor);

8、设置导航条透明,并去掉分割线。-----可以选择上面第4条的方式,让导航条隐藏。然后在设置偏移量。

https://segmentfault.com/a/1190000003482218

9、隐藏导航条下面的那条线

self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
原文地址:https://www.cnblogs.com/fs-ios/p/5021466.html