axiixc
axiixc

Reputation: 1972

-[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)

Upvotes: 15

Views: 3943

Answers (1)

Kyle Clegg
Kyle Clegg

Reputation: 39460

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

Upvotes: 4

Related Questions