Set minimum font size UIButton with margin

I found a solution on how to set the minimum font size to fit the width of my button:

button.titleLabel.numberOfLines = 1; button.titleLabel.adjustsFontSizeToFitWidth = YES; button.titleLabel.lineBreakMode = NSLineBreakByClipping; 

But how to add margin left and right.

Thus, the width of the button label is 200 pt the same as the width of the button. I need my title label to be with spaces on the right and left, so this means that the label width should be, for example, 180 dots, and then I will have 10pt on the right and left.

How can i achieve this?

+1
source share
1 answer

Use titleEdgeInsets :

 button.titleEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right); 

or, in particular, in this case:

 button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10); 
+4
source

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


All Articles