Question

I am using UIAppearance as introduced in iOS 5 to set a custom background image for all the BarButtonItems in my app.

The following code is what I use to set it for the back button, and it works fine in portrait mode. However, when the phone is rotated to landscape and the navigation bar is resized, the button does not get resized at all and is cut off at the bottom.

I thought it would do this automatically since I set the edge insets to not care about vertical resizing. Any ideas?

UIImage *colorViewBBIImage = [[UIImage imageNamed:@"backButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 17, 0, 7)]; 

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:colorViewBBIImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

My non-retina image is 30px x 31px.

Was it helpful?

Solution

For landscape mode, just call the second line of your code with last parameter UIBarMetricsLandscapePhone

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:colorViewBBIImage forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top