Long title, hopefully a little problem.
I have a UINavigationBar with a custom background image. My application will support landscape orientation as well as portrait. The landscape works well in the simulator for the retina of 3-inch and non-mesh screens. However, on a 4-inch retina screen, the background image is doubled in size in landscape mode.
Here is the corresponding code snippet from my user init-method navigation controller:
[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar-bg.png"] forBarMetrics:UIBarMetricsDefault]; if (IS_IPHONE_5) { [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar-bg-landscape-iphone5.png"] forBarMetrics:UIBarMetricsLandscapePhone]; } else { [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar-bg-landscape.png"] forBarMetrics:UIBarMetricsLandscapePhone]; }
IS_IPHONE_5 is a macro defined as:
#define WIDTH_IPHONE_5 568 #define IS_IPHONE_5 ([[UIScreen mainScreen] bounds].size.height == WIDTH_IPHONE_5)
Here are 2 screen fragments that could explain things more clearly. When the application opens in portrait mode, everything is in order:

All are reset when changing in landscape mode:

Image dimensions (in pixels, width x height) for the landscape version of the background image:
- navbar-bg-landscape.png: 480x44
- navbar-bg-landscape@2x.png : 960x88
- navbar-bg-landscape-iphone5.png: 1136x88
Or can it be a problem only for the simulator? (Now I do not have a real iPhone 5)
verhage
source share