IOS 8 UINavigationBar Background Image

I am using the following code to position an image in the background of a UINavigation bar:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_background_login.png"] forBarMetrics:UIBarMetricsDefault];

      

Works like a charm in iOS 7, but when I try to use it in the same simulator, but with iOS 8, the background image is not displayed.

Have a new code for iOS 8? I can't find anything on the net.


UPDATE:

I discovered one of the strangest behaviors I have ever seen. When I show and later fire the modalView, the UINavigationBar background image appears.

For more information: I am loading an image into viewDidLoad.

Anyone though?

+3


source to share


2 answers


Try it, it worked for me: -



[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar_background_login.png"] forBarMetrics:UIBarMetricsDefault];

      

+6


source


Using a [UINavigationBar appearance]

UINavigationBar to set the background globally is correct. But keep in mind that the appearance affects only future instances, not already created ones. ... Try to set your appearance code before placing your UINavigationConroller. it should still work.



+2


source







All Articles