Objective C: How to change text color in navigation bar

44,763

Solution 1

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

Solution 2

In iOS 7, just use:

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

Change [UIColor whiteColor] with whatever text color you want

Solution 3

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;

Solution 4

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

Share:
44,763
Zhen
Author by

Zhen

Updated on March 12, 2020

Comments

  • Zhen
    Zhen over 4 years

    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?

  • Zhen
    Zhen almost 13 years
    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 part
  • Zeb
    Zeb about 9 years
    Old answer, use @Erwan's one