自定义字体被剪切在UITabBarItem标题中

时间:2016-05-09 07:56:10

标签: ios objective-c uitabbaritem

在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。有没有人遇到过这个问题,并找到了解决方法?

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

相关问题