how to change the uinavigationbar background color without overriding drawRect:
I am trying to find a way to set a different background color for the different navigation bar in my app (i have a few views with a nav bar each). I am not looking to override drawRect: since this applies globally across the app. Also, using the tintcolor property doesnt help since it applies to the nav bar items only.
self.navigationController.navigationBar.tintColor = [UIColor greenColor];
I have been googling for days and cant find a straight solution to this problem. how come something so simple is so hard? dont understand why its not a property of the uinavbar...
someone please help with a simple solution...thanks!
subclass UINavigationBar and overwrite drawRect, then use the subclass only in places where you want the different color. (and you could have a method that lets you pass the color when you initialize the subclass or something if you want lots of different colors).
#import <QuartzCore/QuartzCore.h> self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:@"navigationBarBackgroundImage"].CGImage; self.navigationController.navigationBar.tintColor = [UIColor orangeColor];
as you were complaining before there is no contents properties. you need to import quartzframework
what happens when you say self.navBar setTintColor:[UIColor greenColor]]; in viewDidLoad of eachView. where navBar is declared as an IBOutlet UINavigationBar linked to the navigation bar in interface builder
self.navigationController.navigationBar.backgroundColor = [UIColor greenColor]; self.navigationController.navigationBar.tintColor = [UIColor greenColor];
is working for me, very easy way.
The code you have is correct. You need to put it where you are creating the navigation controller.