Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-[UIBarButtonItem setTitlePositionAdjustment:forBarMetrics:] ignores vertical offset

I have an application with some custom positioned bars, and as such I'd like to change the standard vertical alignment of the button text. I've tried setting

[buttonItem setTitlePositionAdjustment:UIOffsetMake(0, -22) forBarMetrics:UIBarMetricsDefault]

but nothing changes. Oddly, if I set a horizontal offset, the button moves just fine. It appears only vertical alignment changes are not being respected. Is this a bug on iOS 7? Am I misunderstanding something about the API? I see no documentation saying that the vertical alignment is ignored.

(example project showing the issue)

like image 443
axiixc Avatar asked Mar 23 '14 21:03

axiixc


1 Answers

Unfortunately setTitlePositionAdjustment:forBarMetrics: doesn't appear to take effect. The best workaround I found was to use a UIButton instead, which can be done right in Interface Builder.

  1. Add a UIButton to the UIBarButtonItem and set the font or image, size, etc.
  2. In the Attributes Inspector, set the UIButton's control alignment to right

ib screenshot

  1. Hook the button back up to whatever actions you need
like image 56
Kyle Clegg Avatar answered Oct 22 '22 22:10

Kyle Clegg