Search code examples
iosuibarbuttonitemback-button

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


Solution

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

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, 1.5) forBarMetrics:UIBarMetricsDefault];