3
votes

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

5 Answers

9
votes

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
votes

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
votes

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
votes

In iOS7, you should replace button's color by

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

In swift and iOs 7 and 8 write this:

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