Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background image of navigation bar for all bars

since I updated to xcode 4.2 and iOS 5 following code has no effect:

@implementation UINavigationBar (CustomNavBarBG)
-(void)drawRect:(CGRect)rect{
    UIImage *image = [UIImage imageNamed:@"navbar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    self.tintColor = [UIColor colorWithRed:124/255.0 green:177/255.0 blue:55/255.0 alpha:1.0];
}
@end

@implementation MyAppDelegate
//....

This should apply a background image and color to the navigation bar. But since the update I get the default blue color. I use the three20 framework in my project.

Any idea why this does not work? How can I set the background image for all navigation bars at one place and not in every view controller?

like image 735
UpCat Avatar asked Oct 27 '11 10:10

UpCat


1 Answers

Try setting:

[[UINavigationBar appearance] setBackgroundImage:myImage forBarMetrics:UIBarMetricsDefault];

in your - (void) applicationDidFinishLaunching:(UIApplication *)application


EDIT: Seems helpfull too:

[[UINavigationBar appearance] setTintColor:myColor]; 
like image 92
Totumus Maximus Avatar answered Oct 02 '22 03:10

Totumus Maximus