UIButton Custom Font Issue

I added a custom font to my application and I installed this custom font for some of the buttons by subclassing the custom font in a custom xib font

enter image description here

but when executed on the device, the font automatically adjusts to the top of the entire button.

enter image description here

Here is my font subclass code.

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

}

 @end 

Please help me solve this problem.

Thanks.

0
source share
1 answer

The problem you see is the result of the font title property being too small. You have two options:

  • Edit the font source directly (explained here )
  • Configure the insertion of the insertion of the button header as follows:

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

Just replace TOP, LEFT, BOTTOM, RIGHT your values.

+1
source

Source: https://habr.com/ru/post/1485785/


All Articles