简体   繁体   中英

ios navigation bar backgroundimage

I have the following code that is supposed to set the background image on my navigation bar.

    if ([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] )
    {
        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation-bar-background"] forBarMetrics:UIBarMetricsDefault];
    }
    else
        NSLog(@"WTF");

It works on the iPad but not on an iPhone, on the iPhone it logs WTF ..... same result without the if statement. The iPhone I have is iPhone 4 running ios 6.0, the iPad is iPad 2 with ios 6.0

Any help is appreciated.

Thanks,

You could try this alternate old method

@implementation UINavigationBar (CustomImage)

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

@end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM