Oleksandr Matrosov
Oleksandr Matrosov

Reputation: 27153

Set minimum font size UIButton with margin

I have found solution how to set minimum font size that will correspond to width of my button:

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

But how can I add margin to the left and right side.

So the width of the buttons label is 200 pt the same as the button width. I need my title label to be with the spaces on the right and left side so it means the label width must be 180pt for example and then I will have 10pt on the right and on the left sides.

How can I achieve this?

Upvotes: 2

Views: 3058

Answers (1)

Lyndsey Scott
Lyndsey Scott

Reputation: 37300

Use titleEdgeInsets:

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

or specifically in this case:

button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);

Upvotes: 5

Related Questions