Objective-c – how to change the uinavigationbar background color without overriding drawRect:

iphoneobjective cuinavigationbaruinavigationcontrollerxcode

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!

Best Answer

#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