I am using a UINavigationBar
in my app with UITabBar
.
On the first tab, the navigation bar title is coming properly as a white title with the default background color, but on the second tab it's not working in the same way. I'm not using any code to change the title color or the navigation bar's tintColor
.
First view:
http://img407.imageshack.us/img407/7192/4go.png
Second View:
Why is the second view's UINavigationBar
title drawn in this black color?
The text color of the navigation bar can be changed using two inbuilt classes: navbar-light: This class will set the color of the text to dark. This is used when using a light background color. navbar-dark: This class will set the color of the text to light.
The title color of Navigation Bar can be changed in Storyboard. Go to Attributes inspector of Navigation Controller > Navigation Bar and set the desired color in Title Color menu.
To change the color of the navigation bar and the title text, we can use UINavigationBarAppearance, which is available since iOS 13. We hereby make a class Theme with a static method as follows, which will come in handy when we need it for some setup in our View or elsewhere.
To set the title for navigation bar of your app, all you have to do is call the built-in modifier function, navigationTitle of the view that’s inside the NavigationView as follows: Please note that the navigationTitle modifier function must be used with the View that is inside the NavigationView.
You’d have noticed the back button on the navigation bar is a standard back arrow and a text which is the title of the previous screen. You may not like it such as you may want to eliminate the text or have your own custom back button. So how to do that?
But navigationBarItems is now deemed deprecated according to Apple’s developer documentation and you’re asked to use toolbar instead. So, for the convenience of use, it’s advisable to create your own custom modifier to check the version of iOS to determine what to use.
Generally, you can not change default color of UINavigationBar
Title. In case of If you want to change color of UINavigationBar Title than you need to customize UINavigationBar. so put code for your second ViewController for more Understanding.
EDIT:
After searching, I found that You can change title color of UINavigationBar
by
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
This code is working in iOS5 and later.
Most of the above suggestions are deprecated now, for iOS 7 use -
NSDictionary *textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
[UIColor whiteColor],NSBackgroundColorAttributeName,nil];
self.navigationController.navigationBar.titleTextAttributes = textAttributes;
self.title = @"Title of the Page";
Also, checkout the NSAttributedString.h for various text properties that could be set.
Try this in AppDelegate:
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
This will allow you to change the colors
NSDictionary *navbarTitleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],UITextAttributeTextColor,
[UIColor blackColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(-1, 0)], UITextAttributeTextShadowOffset, nil];
[[UINavigationBar appearance] setTitleTextAttributes:navbarTitleTextAttributes];
Use this bit of code for iOS7 as UITextAttributeTextColor
has been deprecated.
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
This code changes the text of all the navigationBar, with this code the text can be customized 100%.
in appDelegate:
//custom text navBar
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:0x73/255.0 green:0x47/255.0 blue:0x41/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor colorWithRed:0x1D/255.0 green:0x1D/255.0 blue:0x1B/255.0 alpha:1], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"yourFont" size:20], UITextAttributeFont, nil]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With