0

我有以下代码应该在我的导航栏上设置背景图像。

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

它适用于 iPad,但不适用于 iPhone,在 iPhone 上它记录 WTF ..... 没有 if 语句的相同结果。我的 iPhone 是运行 ios 6.0 的 iPhone 4,iPad 是运行 ios 6.0 的 iPad 2

任何帮助表示赞赏。

谢谢,

4

1 回答 1

0

你可以试试这个替代的旧方法

@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
于 2012-11-16T08:11:18.207 回答