1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

UITextFieldの中の文字をサイズによって可変にする

Posted at

前提条件

UITextFieldが左右の制約により適切に突っ張っていること。

バージョンによってやり方が異なる

iOS13より前のバージョン

_placeholder.adjustsFontSizeToFitWidthをUITextFieldに以下のように設定するとプレイスホルダーを含めた文字が小さく表示されます。
スクリーンショット 2020-11-11 17.29.33.png

Min Font Sizeを設定
スクリーンショット 2020-11-11 17.39.29.png

iOS13移行

https://developer.apple.com/documentation/uikit/uitextfield/1619625-adjustsfontsizetofitwidth
UITextFieldのminimumFontSizeを設定し、adjustsFontSizeToFitWidth をtrueにします。

    @IBOutlet weak var textField: UITextField! {
        didSet {
            textField.minimumFontSize = 10
            textField.adjustsFontSizeToFitWidth = true
        }
    }
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?