3

I am unable to change the color of navigation bar back button. Any help? I customized the UINavigationBar class but I'm unable to change the back button color.

UINavigationBar class code

#import 
#import "UINavigationBar.h"

@interface UINavigationBar ( Category )
{

}

.m file code

- (void) drawRect:(CGRect)rect 
{

    [[UIImage imageNamed:@"top.png"] drawInRect:rect];
    self.tintColor = [UIColor colorWithRed:38 green:65 blue:82 alpha:1];    
}

I'm not able to change the color of the back button.

5 Answers 5

9

Using this you can change the color of all of the navigation buttons:

[[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.

Note: Available for iOS 5 and >

2
  • What if I want to set color for back button of selected View? Jul 5, 2013 at 12:44
  • @JayprakashDubey Just put this in the view controller that pushes. Not the view controller where you want to see this back button color. Oct 2, 2013 at 22:11
2

Use this for change back arrow color in Navigation controller

self.navigationController.navigationBar.tintColor = [UIColor colorWithRed: 127.0/255.0f green:127.0/255.0f blue:127.0/255.0f alpha:1.0];
1

You need to use a UIBarButtonItem with a custom view. Something like this:

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 30)];
[button addTarget:target action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"back_button.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"back_button_tap.png"] forState:UIControlStateHighlighted];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];

Then you can put the button to the navigation bar, usually in a controller with UINavigationController:

self.navigationItem.leftBarButtonItem = buttonItem;
0

In iOS7, you should replace button's color by

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
0

In swift and iOs 7 and 8 write this:

 self.navigationController.navigationBar.tintColor = UIColor.whiteColor() //<-- whiteColor is an example!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.