4

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.

J. Doe
  • 12,159
  • 9
  • 60
  • 114

1 Answers1

18

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
aturan23
  • 4,798
  • 4
  • 28
  • 52
DonMag
  • 69,424
  • 5
  • 50
  • 86