I am trying to set the background image of uinavigationbar for the portrait and landscape orientations. I am using the following code:
UIImage *navbarImage = [[UIImage imageNamed:@"navbar"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 9.0, 0, 9.0)];
UIImage *navbarLandscapeImage = [[UIImage imageNamed:@"navbar-landscape"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 9.0, 0, 9.0)];
[[UINavigationBar appearance] setBackgroundImage:navbarImage
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:navbarLandscapeImage
forBarMetrics:UIBarMetricsLandscapePhone];
However, in the iOS5.1 simulator, when I change the orientation from portrait to landscape to portrait, the image that is used is navbar-landscape.png instead of navbar.png.
Here are some example images:
Portrait default:
Change to Landscape:
Change back to Portrait:
Does anyone have an idea of what the problem is here? I am not sure why the wrong image is getting used.
Actually, it turns out that the problem is a bug in the simulator. I tried all of the solutions described above and none made a difference for when the problem gets resolved or not.