【问题标题】:UINavigationBar.layer.contents not working in IOS5, Any idea why?UINavigationBar.layer.contents 在 IOS5 中不起作用,知道为什么吗?
【发布时间】:2012-01-24 06:28:27
【问题描述】:

我正在使用以下代码行放置图像以显示 UINavigationBar 的背景,它在 IOS4 中运行良好,但在 IOS5 设备上无法运行。

 UINavigationBar.layer.contents = (id)[UIImage imageNamed:@"header_bg_green.png"].CGImage;

另外,当我在 IOS 5 模拟器中测试它时,它不显示 UINavigationBar 层的图像。

请帮忙。

谢谢, 吉格

【问题讨论】:

标签: iphone ios4 ios5 xcode4.2 uinavigationbar


【解决方案1】:

在 iOS 5 中,它们改变了您在导航栏中自定义背景的方式。方法是:

- (void)setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics

如果你想在你的应用中同时支持 iOS 4 和 iOS 5,你需要做一些检查(比如使用respondsToSelector),然后有条件地使用旧方式或者这个方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2022-08-23
    • 2013-05-14
    • 2017-10-30
    • 2011-12-16
    • 1970-01-01
    相关资源
    最近更新 更多