Objective C: How to change text color in navigation bar
Asked Answered
E

4

14

I have changed my navigation bar color via the following code

navconFvc.navigationBar.tintColor = [UIColor colorWithHexString:@"faf6f5"];

The code worked but the text color also needs to be changed (see screenshot below). Also the refresh button logo on the right is affected as well

enter image description here

The same issue occurs if I navigate to another page in the stack

enter image description here

Question: How can I change the color of the

  • title text
  • Back button text and
  • right bar button icon color?

After I changed the background color of the navbar?

Encrimson answered 24/7, 2011 at 5:0 Comment(0)
B
15

For the title here's the way:

iPhone Navigation Bar Title text color

And for the custom buttons here's the way:

adding buttons to ui navigation controller bottom bar

Balmung answered 24/7, 2011 at 5:21 Comment(2)
Rincon-Fadul, thanks for the links, the first link works well for me. However, I am still not sure how I can change the button's text color or icon color. For icon, I probably can change the image directly. But what about the back button text color for instance? The link doesn't really explain about that partEncrimson
Old answer, use @Erwan's oneMastery
C
18

In iOS 7, just use:

self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName : [UIColor whiteColor]};

Change [UIColor whiteColor] with whatever text color you want

Coinstantaneous answered 12/3, 2014 at 8:5 Comment(0)
B
15

For the title here's the way:

iPhone Navigation Bar Title text color

And for the custom buttons here's the way:

adding buttons to ui navigation controller bottom bar

Balmung answered 24/7, 2011 at 5:21 Comment(2)
Rincon-Fadul, thanks for the links, the first link works well for me. However, I am still not sure how I can change the button's text color or icon color. For icon, I probably can change the image directly. But what about the back button text color for instance? The link doesn't really explain about that partEncrimson
Old answer, use @Erwan's oneMastery
C
7

To change text color:

_navController.navigationBar.titleTextAttributes 
         = @{UITextAttributeTextColor : [UIColor blackColor]};

Adding refresh button and color it:

UIBarButtonItem *button = [[UIBarButtonItem alloc]
         initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
         target:self action:@selector(reload)];

[button setTintColor:[UIColor blackColor]];
self.navigationItem.rightBarButtonItem = button;

Variables that effect navigation bar background:

_navController.navigationBar.backgroundColor = [UIColor whiteColor];
_navController.navigationBar.tintColor = [UIColor whiteColor];
_navController.navigationBar.translucent = NO;
Chrysotile answered 12/12, 2013 at 18:46 Comment(0)
W
1

I just put together a simple UIViewController subclass that adds a customizable back button that allows you to change text colors. It basically adds some willAppear/willDisappear logic to animate the back button the way the UINavigationController does while using the leftBarButtonItem property. You might extend this to also do the rightBarButtomItem as well.

https://github.com/typeoneerror/BBCustomBackButtonViewController

Willett answered 22/12, 2011 at 8:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.