Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NavigationBar title is coming in black color

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?

like image 840
Rivan Avatar asked Jun 28 '13 07:06

Rivan


People also ask

How do I change the color of my navigation bar text?

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.

How do I change the navigation title text color in Swift?

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.

How to change the color of navigation bar and title text?

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.

How to set the title for navigation bar of your app?

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.

What is the back button on the navigation bar for?

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?

What happened to navigation bar items in iOS?

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.


6 Answers

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.

like image 161
iPatel Avatar answered Oct 19 '22 19:10

iPatel


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.

like image 42
girish_vr Avatar answered Oct 19 '22 19:10

girish_vr


Try this in AppDelegate:

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
like image 23
Tea Avatar answered Oct 19 '22 17:10

Tea


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];
like image 42
William Voll Avatar answered Oct 19 '22 18:10

William Voll


Use this bit of code for iOS7 as UITextAttributeTextColor has been deprecated.

self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor orangeColor] forKey:NSForegroundColorAttributeName];
like image 31
Robert J. Clegg Avatar answered Oct 19 '22 19:10

Robert J. Clegg


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]];
like image 42
Ilario Avatar answered Oct 19 '22 19:10

Ilario