从 iOS 4 切换到 5 时的 NavigationBarStyle 问题
升级到 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 中不起作用?
谢谢
Have a little design issue after having upgraded to iOS 5 and Xcode 4.2
This is how my view looked in iOS 4:
And this is how it looks like in iOS 5:
In my navigation delegate I have the following method to draw the "image" at the top:
- (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)];
}
And inside my controller I set the following:
self.navigationBarStyle = UIBarStyleBlack;
How come it is not working in iOS 5?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在iOS5下,需要使用
UIAppearance
。看看那个。下面是一个有条件地使用它的示例,以便您可以继续支持 iOS4:如您所见,这为所有 UINavigationBar 设置了自定义背景图像。您可以使用 UIAppearance 做很多事情。您需要保留当前在
drawRect:
中执行的所有自定义操作,因为 iOS4 之前的设备仍将使用该操作,而不是新的 UIAppearance 代码。Under iOS5, you need to use
UIAppearance
. Have a look at that. Here's an example for using it conditionally so that you can continue to support iOS4:As you can see, this sets a custom background image for all UINavigationBars. There are lots of things you can do with UIAppearance. You'll want to keep any custom stuff you're currently doing in
drawRect:
since pre-iOS4 devices will still use that and not the new UIAppearance code.