【问题标题】:Custom font being clipped in UITabBarItem title在 UITabBarItem 标题中剪辑的自定义字体
【发布时间】:2016-05-10 20:43:37
【问题描述】:

在 UITabBarItem 中使用某些自定义字体时,我看到一些字符在底部被剪裁。我也在 UIButton 上看到了这种情况,但找到了一个解决方法,即继承 UIButton 并覆盖以下方法:

custom font on UIbutton title clipped on top of word

-(void)layoutSubviews
{
    [super layoutSubviews];

    CGRect frame = self.titleLabel.frame;
    frame.size.height = self.bounds.size.height;
    frame.origin.y = self.titleEdgeInsets.top;
    self.titleLabel.frame = frame;
}

很遗憾,layoutSubviews 无法覆盖 UITabBarItem。有没有人遇到过这个问题并找到了解决方法?

【问题讨论】:

    标签: ios objective-c uitabbaritem


    【解决方案1】:

    您可以使用属性字典(setTitleTextAttributes:forState:,继承自 UIBarItem)自定义标题(包括其颜色),您可以使用 setTitlePositionAdjustment(_:forBarMetrics:) 属性调整标题的位置。

    【讨论】:

    • 我尝试了各种 titlePositionAdjustment 设置,但它不是导致剪辑的位置。我尝试了不同的字体,标准的 Helvetica 可以正常工作,没有剪裁,某些其他字体也可以正常工作。我必须使用客户设计指南要求的自定义字体。
    • 您也可以创建一个自定义按钮并用它初始化 UIBarButtonItem。 UIBarButton: var view = // create your custom viewvar btnMenu = UIBarButtonItem(customView: view)
    【解决方案2】:

    基本上是字体垂直间距问题。您必须使用字体属性计算总字体高度,因为每个字体属性都不同。你从苹果文档中得到字体高度的想法帮助你。 Font Metrics

    【讨论】:

      猜你喜欢
      • 2021-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      相关资源
      最近更新 更多