I ran into this issue in iOS 8 where the wrong background image for the navigation bar is displayed in any of these situations:
- the view controller-based status bar appearance is set to
YES
(default) and the navigation controller is presented modally. - the view controller-based status bar appearance is set to
NO
and the status bar is initially hidden. In this case, the navigation controller does not need to be presented modally to display the wrong image.
To isolate the problem where the view controller-based status bar appearance is set to YES (default) and the navigation controller is presented modally I created a test project from scratch following these steps:
Create a new project with the "Master-Detail Application" template.
Open
Main.storyboard
and add a Navigation Controller to it. Remove its root view controller and connect the Master View Controller with a modal segue. Then connect the Detail View Controller as its root view controller. You should end up with something like this:
Customise the navigation bar background via the appearance proxy. Use two different images for portrait (
UIBarMetricsDefault
) and landscape (UIBarMetricsCompact
). I used a category onUIImage
to create the images from solid colors.- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor redColor]] forBarMetrics:UIBarMetricsDefault]; [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor blueColor]] forBarMetrics:UIBarMetricsCompact]; return YES; }
Run the app. The Master view controller displays the right navigation bar background images for portrait and landscape orientations:
Now present the Detail view controller modally. To do so, tap on the "Add" button and then select the newly created row. The Detail view controller displays the right navigation bar background image.
Rotate the interface. The Detail view controller will not change the navigation bar background image (wrong):
- Rotate the interface back to its original orientation. The Detail view controller will change the navigation bar background image (wrong):
Has anyone else struggled with this?