Cas*_*nge 1 iphone coding-style navigationbar ios
升级到iOS 5和Xcode 4.2后出现一些设计问题
这就是我在iOS 4中查看的视图:
这就是它在iOS 5中的样子:
在我的导航委托中,我有以下方法在顶部绘制"图像":
- (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 设置了自定义背景图像.你可以用UIAppearance做很多事情.您需要保留当前正在进行的任何自定义操作,drawRect:因为iOS4之前的设备仍将使用该设备,而不是新的UIAppearance代码.
| 归档时间: | 
 | 
| 查看次数: | 466 次 | 
| 最近记录: |