iOS 5 [UINavigationBar 外观] setBackgroundImage 不起作用
我在 Xcode 4.2 Build 4D199 中创建了一个新的测试 iOS5 项目,并尝试如上所述设置 UINavigationBar 的外观,但没有任何反应。
我在 viewDidLoad 中尝试的代码:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar-iphone.png"] forBarMetrics:UIBarMetricsDefault];
让它工作的唯一方法是设置 UINavigationBar 实例的外观。比如:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar-iphone.png"] forBarMetrics:UIBarMetricsDefault];
发生什么事了?还有其他人遇到过这个问题吗?
I created a new test iOS5 project in Xcode 4.2 Build 4D199 and tried to set the appearance of the UINavigationBar
as described above, but nothing happens.
The code I tried in the viewDidLoad
:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar-iphone.png"] forBarMetrics:UIBarMetricsDefault];
The only way I can get it to work is to set the appearance on the instance of the UINavigationBar
. Like:
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar-iphone.png"] forBarMetrics:UIBarMetricsDefault];
What is going on? Has anyone else had this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
viewDidLoad
是干扰导航控制器导航栏的appearance
代理的错误位置。在创建导航控制器之前就执行此类操作。在应用程序委托的applicationDidFinishLaunching
中是一个好地方。viewDidLoad
is the wrong place to be messing with theappearance
proxy of a navigation controller's navigation bar. Do this sort of thing before the navigation controller is even created. In your app delegate'sapplicationDidFinishLaunching
is a good place.您是否仔细检查过该图像文件是否存在?
Did you double-check if that Imagefile does exist?
您需要提供 forBarMetrics: 才能使其工作。
You will need to provide forBarMetrics: for this to work.