UIButton Custom font issue

老子叫甜甜 提交于 2020-01-25 07:07:25

问题


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

Please guide me to fix this issue.

Thanks.


回答1:


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

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

Just substitute TOP, LEFT, BOTTOM, RIGHT with your values.



来源:https://stackoverflow.com/questions/13822128/uibutton-custom-font-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!