简体   繁体   中英

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.

为按钮对象添加以下行:

button.titleLabel?.adjustsFontSizeToFitWidth = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM