11

I am trying to set the text in my UIButton programmatically, but the text becomes abbreviated when displayed in the button. Is there a way to adjust the font size of the text in the button to fit the width, through code? I have checked other questions, but the answers do not solve my problem. Thanks.

Janmenjaya
  • 4,149
  • 1
  • 23
  • 43
muyiwa adenaike
  • 139
  • 1
  • 1
  • 6

2 Answers2

16

Add this line for button object:

button.titleLabel?.adjustsFontSizeToFitWidth = true
Kampai
  • 22,848
  • 21
  • 95
  • 95