hanumanDev
hanumanDev

Reputation: 6614

Trying to override the UINavigationBar in the AppDelegate implementation file

I'm trying to override the UINavigationBar and add a custom image. I added this to my AppDelegate file and then also to the implementation file. Neither work and I'm unsure why.

any help would be great :)

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed: @"redbar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end

Upvotes: 0

Views: 210

Answers (1)

Johan Persson
Johan Persson

Reputation: 56

For iOS 5 and later do the following..

if ([[UINavigationBar class]respondsToSelector:@selector(appearance)]) {
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"redbar.png"] 
                                       forBarMetrics:UIBarMetricsDefault];
}

Upvotes: 1

Related Questions