UINavigationBar.layer.contents 在 IOS5 中不起作用,知道为什么吗?

发布于 2024-12-29 00:13:25 字数 277 浏览 2 评论 0原文

我使用以下代码行来放置图像以显示 UINavigationBar 的背景,它在 IOS4 中工作正常,但在 IOS5 设备上不起作用。

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

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

请帮忙。

谢谢, 吉格尔

I am using the following line of code to place image to show background of a UINavigationBar, it works fine in IOS4 but not working on devices with IOS5.

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

Also when i test it in IOS 5 Simulator it do not show image for UINavigationBar layer.

Please help.

Thanks,
Jigar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万劫不复 2025-01-05 00:13:25

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

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

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

In iOS 5 they changed the way you do custom backgrounds in navigation bars. The method is:

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

If you want to support both iOS 4 and iOS 5 in your app, you'll need to do some kind of check (such as using respondsToSelector), and then conditionally use either the old way or this method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文