user3532505
user3532505

Reputation: 419

UIButton with dynamic font size support

I'm trying to use dynamic font size on a UIButton. But if I increase the font size, the text on the button gets truncated to "...".

Any idea on how to fix this? Thanks 🙂

Upvotes: 1

Views: 1949

Answers (2)

AechoLiu
AechoLiu

Reputation: 18368

You can get the UILabel of UIButton by

let btn = UIButton() ....
if let label = btn.textLabel {
    label.adjustsFontSizeToFitWidth = true // Adjust font size automatically
    label.minimumScaleFactor = 0.5 //< The minimum font size scale factor 
}

Reference

  1. adjustsFontSizeToFitWidth property
  2. minimumscalefactor property
  3. UILabel reference

Upvotes: 3

user3532505
user3532505

Reputation: 419

Use a constraint with height greater than or equal

Upvotes: 0

Related Questions