textField
は中身を全部消すことができるclearButton
が実装できます。
画像の右端にあるバツマークです
これの表示パターンは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の部分を変更すれば実装できます