Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS 5 How to change the color of back button in a navigation bar?

I want to change the color of back button of a navigation bar to make it look like thisenter image description here

like image 979
Nilesh Tupe Avatar asked Oct 28 '11 12:10

Nilesh Tupe


2 Answers

Set the backBarButtonItem's tintColor:

self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor];

TIP: If you want this to be applied to all UIBarButtonItem instances in your application by default, then you can use the new UIAppearance API to do just that:

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];
like image 96
Jacob Relkin Avatar answered Sep 17 '22 17:09

Jacob Relkin


The first line of jacob's answer didn't work for me because the backBarButtonItem was NULL. It is NULL because it's been created later automatically when switching to an other ViewController. At that time you can set the title of the button with

self.title = @"nice title"; // self is here the view(controller) within the popoverController

but you can't set the tintColor.

What worked for me, was to create a new UIBarButtonItem without any style. Then set the title and color propertys and set it as backBarButtonItem.

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = @"go back - now!";
backButton.tintColor = [UIColor colorWithRed:0.1 green:0.5 blue:0.7 alpha:1.0];
self.navigationItem.backBarButtonItem = backButton;
[okButton release];
like image 37
svn Avatar answered Sep 21 '22 17:09

svn