iOS - UIBarButtonItem - 后退按钮标题垂直位置不调整 [英] iOS - UIBarButtonItem - Back Button title vertical position not adjusting

查看:81
本文介绍了iOS - UIBarButtonItem - 后退按钮标题垂直位置不调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 UIAppearance 在我的 UIBarButtonItem 对象中设置自定义字体。这很好,并正确设置字体。但是,我需要调整按钮标题的垂直位置以适应新字体的大小。

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];

问题是标题的垂直位置在常规 UIBarButtonItem中正确调整,但导航栏上的后退按钮无法调整。我假设我在我的代码中定位了正确的对象,因为它的字体更新了,而不是它的标题的垂直位置。

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?

谢谢

Brian

推荐答案

我也有这个问题,我使用以下方法解决了这个问题:

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

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

这篇关于iOS - UIBarButtonItem - 后退按钮标题垂直位置不调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆