Search code examples
iosuinavigationbaruinavigationitem

navigationItem titleView - Logo too big for iPhone6+


I'm adding a logo in the navigation bar.

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"00-logo"]];
self.navigationItem.titleView = imageView;

It looks okay with iPhone4S, iPhone5S, iPhone6 but in iPhone6+ it's a little bit too big, so there are some pixels below the nav bar.

I tried with:

[self.navigationItem.titleView sizeToFit];

But still doesn't work.

The images I'm using for the logo are:


Solution

  • Your 3x image has the wrong dimensions compared to the 2x image.

    Remember, if the 1x image is w x h pixels, the 2x image must be 2w x 2h pixels and the 3x image must be 3w x 3h pixels.

    Given your 2x image of 203 x 72, your 3x image must be 304.5 x 108 pixels, not 393 x 138.

    Note that 2x images should have even widths and heights.