简体   繁体   中英

How to change navigation bar title color?

I tried to change title color like this, but it has no effect.

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

Maybe the problem that navigationbar style is black?

self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

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

Try this :

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

Try to use an instance of controller's navigationBar

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM