Search code examples
iphoneuinavigationbaruibarbuttonitemuinavigationitemtitleview

UIBarButtonItem height in landscape iPhone


I have a nav bar in an iPhone app with a custom UIBarButtonItems in it:

UIBarButtonItem* homePersonButton = [[UIBarButtonItem alloc]
       initWithImage:[UIImage imageNamed:@"homePerson.png"]
               style:UIBarButtonItemStylePlain
              target:self action:@selector(showHomePerson)];

The homePerson.png is 20 x 18.

It looks good in portrait mode, but in landscape mode the 20x18 image on the button is too tall to look nice. It looks like iOS does some work on their standard buttons to shrink the image as needed when it is in a thinner nav bar.

What is the best way to handle this?

Another example is when I have a custom button in the titleView of the nav bar. I need it to shrink as well when the app rotates.

Thanks in advance for any pointers you can give me!


Solution

  • The size of a toolbar and navigation bar image is 20 x 20 so when you're providing an image that does not meet those dimensions you're leaving up to the framework to resize/scale your image which is causing your problem. Resize/scale your image to 20x20 and your image should look correct in both portrait and landscape.