In my app I am overriding the uinavigationbar color in the AppDelegate to create this color across the entire app:
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIColor *color = [UIColor colorWithRed:0.16
green:0.20
blue:0.32
alpha:1];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColor(context, CGColorGetComponents( [color CGColor]));
CGContextFillRect(context, rect);
[self setBarStyle:UIBarStyleBlack];
[self setTintColor:color];
}
However, in one of my views, i would like to change the color of one of the nav bar items to another color, different from the global color above, but only for one of the items – the bar color should stay the same (reasoning – i’d like to have a nav bar item in green and a “On” text and change it to red with an “Off” text based on the user input).
I tried to override the color of the button in my view in the following way, but it doesnt seem to do anything.
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
}
Does anyone have a suggestion (or a better way) to make this happen?
Cheers.
It is tested code which will work 100%.
//in below code u can set the different image for different color
or
simply
fill the color by your question code.
here below is for put image in navigation bar
u can customize by removeing the picture code and puttting ur above code with different color.that it .logic is same
CustomNavigation.h
CustomNavigation.m
if u want to First.png to set navigationBar background image in FirstViewController then
in ur FirstViewController.m
if u want to Second.png to set navigationBar background image in SecondViewController then
in ur SecondViewController.m