升级到iOS 5和XCode 4.2后,有一个小小的设计问题

这就是我在iOS 4中的看法:

1 http://casperslynge.dk/1

这就是iOS 5中的样子:

2 http://casperslynge.dk/2

在我的导航委托中,我有以下方法在顶部绘制“图像”:

- (void)drawRect:(CGRect)rect {
    UIImage *image;
    if(self.barStyle == UIBarStyleDefault){
        image = [UIImage imageNamed: @"topbar_base.png"];
    }
    else{
        image = [UIImage imageNamed: @"nyhedsbar_base.png"];    
    }
    [image drawInRect:CGRectMake(-1, -1, self.frame.size.width+3, self.frame.size.height+3)];
}

在我的控制器内部,我设置以下内容:

self.navigationBarStyle = UIBarStyleBlack;

怎么在iOS 5中不起作用?

谢谢

有帮助吗?

解决方案

在ios5下,您需要使用 UIAppearance. 。看看那个。这是有条件使用它的示例,以便您可以继续支持ios4:

// iOS5-only to customize the nav bar appearance
if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) {
    UIImage *img = [UIImage imageNamed: @"NavBarBackground.png"];
    [[UINavigationBar appearance] setBackgroundImage:img forBarMetrics:UIBarMetricsDefault];
}

如您所见,这设置了一个自定义背景图像 全部 uinavigationbars。您可以使用很多事情来做很多事情。您需要保留您当前正在做的任何自定义工作 drawRect: 由于PRE-IOS4设备仍将使用它,而不是新的Uiappearance代码。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top