Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum scale factor for title of UIButton does not apply

This is my text in side of a UIButton:

enter image description here

It should says "highscores", but it is okay now since it is in Storyboard and not running. My constrains are as followed:

enter image description here

The proportional width is 0.3 of the superview. I settled this in my viewDidLoad:

highscoresButton.titleLabel!.minimumScaleFactor = 0.5

But the simulator shows exactly the same as the storyboard. When applying a minimum scale factor for UILabels it works correctly. What am I doing wrong here? Thank you. Changing the minimum scale factor to 0.1 has also no effect.

like image 499
J. Doe Avatar asked Dec 04 '22 22:12

J. Doe


1 Answers

Buttons are a little quirky... This won't change it in Storyboard without some effort turning it into a custom IBDesignable control, but should get where you want at runtime.

btn.titleLabel!.font = UIFont(name: "Your Font", size: 50.0)
btn.titleLabel?.minimumScaleFactor = 0.1
btn.titleLabel?.numberOfLines = 1
btn.titleLabel?.adjustsFontSizeToFitWidth = true
btn.titleLabel?.lineBreakMode = NSLineBreakMode.byClipping
like image 57
DonMag Avatar answered Jan 05 '23 00:01

DonMag