I have an issue with my navigation bar, the UIBarButtonItem is not correctly vertically aligned. I don't know why because I'm using a simple UIBarButtonItem and not a custom view. See my code below and thanks for your help!
UIBarButtonItem *newGameItem = [[UIBarButtonItem alloc] initWithTitle:@"New Game" style:UIBarButtonItemStyleDone target:self action:@selector(newGame)];
self.navigationItem.rightBarButtonItem = newGameItem;
I had a similar issue: We use custom fonts via
UIAppearance
for both navigation titles and bar button items, and in some cases, the right item was vertically misaligned.I could easily fix the misalignment by using
[self.navigationItem setRightBarButtonItem:rightItem animated:YES]
instead of the property setter.Unfortunately, there is not much you can do about
UIBarButtonItem
vertical spacing. I believe you'll have to either increase the font size of your title on theUINavigationBar
(you can do this withUIAppearance
also), or decrease the font size of yourUIBarButtonItem
.I had the same problem with a button on the left, I was able to fix it in Xcode 6.3.1: select the button (bar button item) right column tab "ruler" inset image Top value: -54 instead of 0. Note that: my device is an iPhone4 with iOS 7, the button was perfectly in place in Xcode and misplaced on the device, now it is in place on the device and misplaced in Xcode
Actually there are couple ways to align the bar buttons. Try to adjust the button title position with this:
-10 -10 - just for example
OR
you can initialize your
newGameItem
with customUIButton
. The custom button is a subclass of UIButton with this method overriddenthen initialize your
newGameItem