Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - UIBarButtonItem - Back Button title vertical position not adjusting

I am setting a custom font in my UIBarButtonItem objects using UIAppearance. This works fine and sets the font correctly. However, I do need to adjust the button title's vertical position to cater for the sizing of the new font.

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIFont fontWithName:@"Sketch Rockwell" size:12] forKey:UITextAttributeFont] forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, 1.5) forBarMetrics:UIBarMetricsDefault];

The problem is that the title's vertical position is adjusted correctly in a regular UIBarButtonItem, but the back buttons on the navigation bar do not get adjusted. I presume that I am targeting the correct object in my code because its font gets updated, just not its title's vertical position.

Does anyone have an idea of how to target the back buttons directly?

Thanks

Brian

like image 513
Brian Boyle Avatar asked Apr 19 '12 16:04

Brian Boyle


1 Answers

I had this issue too, I fixed it by using:

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 1.5) forBarMetrics:UIBarMetricsDefault];
like image 124
Fringley Avatar answered Nov 15 '22 17:11

Fringley