- 在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];
- 设置导航栏背景色效果
[[UINavigationBar appearance] setBarTintColor:[UIColor orangeColor]]
![](https://img2020.cnblogs.com/blog/831196/202104/831196-20210421131734668-274613285.png)
- 设置导航栏的 item 颜色
[[UINavigationBar appearance] setTintColor:[UIColor yellowColor]]
![](https://img2020.cnblogs.com/blog/831196/202104/831196-20210421131844825-1369884788.png)
- 设置导航标题文字属性
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]}]
![](https://img2020.cnblogs.com/blog/831196/202104/831196-20210421131942133-1131092336.png)
- 设置导航栏半透明属性
// 设置半透明为YES
[[UINavigationBar appearance] setTranslucent:YES]
![](https://img2020.cnblogs.com/blog/831196/202104/831196-20210421132127900-2125873210.gif)
- 设置半透明为 NO ,没有出现导航栏背景色变化状态.
[[UINavigationBar appearance] setTranslucent:NO]
![](https://img2020.cnblogs.com/blog/831196/202104/831196-20210421132304241-669689312.gif)
解决方法来自: https://stackoverflow.com/a/48556889/6302512