UIButton自定义字体问题 [英] UIButton Custom font issue

查看:83
本文介绍了UIButton自定义字体问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中添加了自定义字体,并通过将自定义字体子类化为完美设置的xib自定义字体来为某些按钮设置了自定义字体

I have added a custom font in to my application and i set that custom font for some of the buttons by sub classing the custom font,in xib custom font set perfectly

但是在设备中执行时,字体会在所有按钮中自动调整为向上.

but while execute in device the font auto adjust to upside in all the button.

这是我的自定义字体子类代码.

Here is my custom font sub class code.

@interface ButtonWithBebasNeueFont : UIButton 
@end
@implementation ButtonWithBebasNeueFont

- (void)awakeFromNib 
{
    [super awakeFromNib];
    self.titleLabel.font = [UIFont fontWithName:@"BebasNeue" size:self.titleLabel.font.pointSize];

}

@end

请指导我解决此问题.

谢谢.

推荐答案

您看到的问题是字体的ascender属性太小的结果.您有两种选择:

The problem you're seeing is a result of the font's ascender property being too small. You have two options:

  1. 直接编辑字体源(在此处说明)
  2. 像这样设置按钮的标题边缘插图:

  1. Edit the font source directly (explained here)
  2. Set the title edge insets of the button like so:

self.titleEdgeInsets = UIEdgeInsetsMake(TOP, LEFT, BOTTOM, RIGHT);

只需将TOP, LEFT, BOTTOM, RIGHT替换为您的值.

这篇关于UIButton自定义字体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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