如何设置全局navigationbar的颜色

  • 在appdlegate.m中的 didFinishLaunchingWithOptions方法中添加如下代码
 // 设置导航栏背景色
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
// 设置导航栏的 item 颜色
    [[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
// 设置导航标题文字属性
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]}];
// 设置导航栏是否半透明, 如果为YES 则会出现下方导航栏背景色有一个变化的状态. 设置为NO 则不会出现
    [[UINavigationBar appearance] setTranslucent:NO];
  1. 设置导航栏背景色效果
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]]

  1. 设置导航栏的 item 颜色
[[UINavigationBar appearance] setTintColor:[UIColor yellowColor]]

  1. 设置导航标题文字属性
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]}]

  1. 设置导航栏半透明属性
// 设置半透明为YES
[[UINavigationBar appearance] setTranslucent:YES]

  • 设置半透明为 NO ,没有出现导航栏背景色变化状态.
[[UINavigationBar appearance] setTranslucent:NO]

解决方法来自: https://stackoverflow.com/a/48556889/6302512

原文地址:https://www.cnblogs.com/adampei-bobo/p/14684829.html