@tamago1603

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

Swift Storybord UIButtonにadjustsFontSizeToFitWidthが効かない

storybordにてUIButtonの文字を可変にしたい

タブレットと小さめのIphoneで開いた際に文字の大きさを可変にしたいため、UIButtonを設置しadjustsFontSizeToFitWidth = trueを記載したが文字の大きさは何も変わらなかった。

minimumScaleFactor = 0.5
lineBreakMode = .byClipping等も試してみたが上手くいかなかった。

UILabelのautoshrinkのように
UIButtonで端末によって文字の大きさを変えることは不可能なのでしょうか。
UIKITで作成しています。

【storybordとコード】
スクリーンショット 2025-11-14 17.08.10.png

【シュミレータ】
IMG_2943.png

※自身の想定だとTabletより文字が小さくなると思っていたが現状全く同じ大きさになっているに見える

0 likes

1Answer

  • setTitle()を使ってみてはどうですか。

    button.titleLabel?.adjustsFontSizeToFitWidth = true
    button.titleLabel?.text = "hogehoge"                         // NG
    button.setTitle("hogehoge", for: UIControl.State.normal)     // OK
    
0Like

Your answer might help someone💌