Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the color of backBarButtonItem?

In my application I want to change the color of bacBarButtonItem. Is it possible to change the color? or I have to put an image of it. and in case of image tell me the code how to put the image.

like image 253
iPhone Avatar asked Dec 03 '22 07:12

iPhone


2 Answers

If you just want to change the color you can do it with this line of code.

[[UIBarButtonItem appearance] setTintColor:[UIColor redColor]];

Replace redColor with the following to adjust the color of the buttons:

colorWithRed:0/255.0 green:144/255.0 blue:200/255.0 alpha:1.0// pick your color using this

Be sure to put this in the view controller that pushes. Not the view controller where you want to see this back button color.

like image 131
SirRupertIII Avatar answered Dec 14 '22 14:12

SirRupertIII


Praveen-K answer is right, but take in mind that you'll have to do it in every viewcontroller.

Starting at iOS5, Apple have introduced the "appearance" concept.

- (void)setBackButtonBackgroundImage:(UIImage *)backgroundImage forState:(UIControlState)state barMetrics:(UIBarMetrics)barMetrics __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;

In your case would be something like this

UIImage *image = [UIImage imageNamed:@"imageName.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:image forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

But as I said, Praveen-K answer is ok and will work, but just to let you know for the future.

like image 24
Yorxxx Avatar answered Dec 14 '22 16:12

Yorxxx