如何更改导航栏标题颜色?

时间:2017-03-16 08:20:26

标签: ios objective-c uinavigationcontroller uinavigationbar

我试图改变这样的标题颜色,但它没有效果。

NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];

也许导航栏样式是黑色的问题?

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

3 个答案:

答案 0 :(得分:0)

使用UITextAttributeTextColor而不是NSForegroundColorAttributeName作为密钥,它将起作用:)

答案 1 :(得分:0)

试试这个:

self.navigationItem.title = @"The title";
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor redColor] forKey:NSForegroundColorAttributeName];

答案 2 :(得分:-1)

尝试使用控制器的navigationBar实例

UIFont* font = kRobotoMedium(21));
[controller.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:font}];