2

When using certain custom fonts in a UITabBarItem i'm seeing some of the characters being clipped at the bottom. I also saw this occuring on UIButton's but found a fix for that which was to subclass the UIButton and override the following method:

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

Unfortunately layoutSubviews isn't available to override on a UITabBarItem. Has anyone experienced this problem and found a fix for it?

Community
  • 1
  • 1
Andy Davies
  • 4,287
  • 5
  • 24
  • 31

2 Answers2

0

You can customize the title (including its color) with an attributes dictionary (setTitleTextAttributes:forState:, inherited from UIBarItem), and you can adjust the title’s position with the setTitlePositionAdjustment(_:forBarMetrics:) property.

Tomasz Nazarenko
  • 1,064
  • 13
  • 31
  • I've tried various titlePositionAdjustment settings and it's not the position that it causing the clipping. I've tried different fonts the standard one Helvetica works fine with no clipping and certain other ones work fine as well. I have to use the custom font as required by the clients design guidelines. – Andy Davies May 10 '16 at 11:57
  • You can also create a custom button and initialise UIBarButtonItem with it. `UIBarButton: var view = // create your custom view` `var btnMenu = UIBarButtonItem(customView: view)` – Tomasz Nazarenko May 10 '16 at 12:28
0

It's basically fonts vertical spacing issue. You have to calculate total font height using property of font, for every font property are different. you get idea for font height from apple documents help you. Font Metrics

Dhaval Patel
  • 95
  • 12