yjsoon
yjsoon

Reputation: 849

UIBarButtonItem shifting downwards after a UINavigationController push

My app runs in a UINavigationController. When I push in a new view controller from the right, the top right UIBarButtonItem (Edit) shifts down by 1 pixel — the Edit button stays in place, but the graphic noticeable shifts down.

I've noticed this only happens after I set up a UIAppearance proxy for the bar button item. This is my code for doing that:

UIImage *barButton = [[UIImage imageNamed:@"navBarBarButton"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:barButton
                                        forState:UIControlStateNormal
                                      barMetrics:UIBarMetricsDefault];

navBarBarButton.png is a 52x31 bar button image.

Other potentially relevant info:

Has anyone seen this, know why this is happening, or how to prevent the button from shifting? Thanks.

Upvotes: 3

Views: 915

Answers (2)

lumenela
lumenela

Reputation: 131

I had the issue when font size was 18. After I've changed it to 19 shifting is gone and navigation bar transitions smoothly.

Upvotes: 1

yjsoon
yjsoon

Reputation: 849

In case anyone gets here with the same issue, I managed to fix the issue by having my barButton image at the standard 30px height (instead of 31, as above).

Upvotes: 3

Related Questions