0
2

More than 3 years have passed since last update.

[Swift] textFieldのclearButtonMode

Posted at

textFieldは中身を全部消すことができるclearButtonが実装できます。
画像の右端にあるバツマークです
スクリーンショット 2020-08-24 18.36.53.png

これの表示パターンはclearButtonModeの設定で変更することができます。

.always

.alwaysはtextFieldに文字列があれば常に出現します。

textField.clearButtonMode = .always

.never

.neverはボタンを表示しません

textField.clearButtonMode = .never

.unlessEditing

.unlessEditingはtextFieldに文字列があり、textFieldが選択されていない時に出現します

textField.clearButtonMode = .unlessEditing

.whileEditing

.whileEditingはtextFieldに文字列があり、textFieldが選択されている時に出現します

textField.clearButtonMode = .whileEditing

storyboard上での実装

textFieldのClearButtonの部分を変更すれば実装できます

スクリーンショット 2020-08-24 19.01.19.png

0
2
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
0
2