2
votes

How can I set different background images for the navigation bar in a detail split view for when it is in landscape as opposed to portrait?

Here is the code I use

[self.topNavbar setBackgroundImage:[UIImage imageNamed:@"nav-bar-portrait-ipad"]
                                   forBarMetrics:UIBarMetricsDefault];
[self.topNavbar setBackgroundImage:[UIImage imageNamed:@"nav-bar-landscape-ipad"]
                                   forBarMetrics:UIBarMetricsLandscapePhone];

UIBarMetricsLandscapePhone is never called when a splitView is rotated to landscape. The width of the detailView in portrait (768 px) mode is different to landscape mode (704 px), so how are we meant to set a different image for each?

1

1 Answers

2
votes

The navigation bar doesn't change height in different orientations on the iPad, so there are no separate bar metrics (there's no need for an image of different height).

On the iPhone, a navigation bar is shorter in landscape than in portrait, so different images are required (gradient images don't scale well). Navigation backgrounds are typically the same all the way across, so the width isn't usually a consideration.

If you want to change the image on rotation, you'll have to do it in response to a rotation event.