Timur Mustafaev
Timur Mustafaev

Reputation: 4929

Change UINavigationBar background image to default - iOS 4.3

I change UINavigationBar background image with overloaded method

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

@end

But in some UIViewControllers I need to remove this background image. How I can do it?

Upvotes: 2

Views: 1990

Answers (2)

Jonas Schnelli
Jonas Schnelli

Reputation: 10005

You might look at this blog post from Sebastian Celis. It solves exactly the problem your facing.

And maybe also check this.

Upvotes: 2

WhiteTiger
WhiteTiger

Reputation: 1691

test in this way

+ (void)setNavigationbarBackground:(UINavigationBar *)nBar imageName:(NSString *)imgName {
    if([nBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]) {
        [nBar setBackgroundImage:[UIImage imageNamed:imgName] forBarMetrics:UIBarMetricsDefault];
    } else {
        [nBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:imgName]]];
    }
}

Upvotes: 0

Related Questions