更改NavigationBar颜色(背景颜色)

use*_*305 6 iphone xcode objective-c

我一直在阅读以更改导航栏上的默认颜色,我只需要将appdelegate中的第一个方法更新为此

self.window.rootViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)

但它似乎没有用,所以我尝试在firstview的viewDidLoad方法中设置它:

self.parentViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)

这也不起作用.我怎么能改变这个?

Dru*_*erB 6

不要使用self.parentViewController,但是self:

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)


gra*_*ver 0

Tryself.navigationController.navigationBar.tintColor = [UIColor whiteColor];
UIViewController类有一个属性navigationController,它返回其嵌入的导航控制器,无论深度如何,否则返回nil