iOS 5 [UINavigationBar appearance] setBackgroundImage does not do work

天涯浪子 提交于 2019-12-19 08:09:07

问题


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?


回答1:


viewDidLoad is the wrong place to be messing with the appearance proxy of a navigation controller's navigation bar. Do this sort of thing before the navigation controller is even created. In your app delegate's applicationDidFinishLaunching is a good place.




回答2:


Did you double-check if that Imagefile does exist?




回答3:


You will need to provide forBarMetrics: for this to work.



来源:https://stackoverflow.com/questions/7855365/ios-5-uinavigationbar-appearance-setbackgroundimage-does-not-do-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!