简体   繁体   中英

UIButton Custom font issue

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM