Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust font size of text in a UIButton to fit the width programmatically in Swift?

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.

like image 673
muyiwa adenaike Avatar asked Dec 19 '14 07:12

muyiwa adenaike


1 Answers

Add this line for button object:

button.titleLabel?.adjustsFontSizeToFitWidth = true
like image 153
Kampai Avatar answered Oct 02 '22 19:10

Kampai