LoginSignup
2
2

More than 5 years have passed since last update.

Text Fieldでフォーカスが当たった際に入力されてる値が消えないようにする

Last updated at Posted at 2017-11-09

環境

Xcode9.1

解決

Inspectorから解決する方法とCode中で解決する方法がありました

Inspectorから解決

Text FieldのInspectorで、Clear Buttonの下にある Clear When editing beginsのチェックを外す

Codeで解決

clearsOnBeginEditingプロパティをfalseにする

@IBOutlet weak var textField: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    textField.clearsOnBeginEditing = false
}

因みに

InspectorでClear When editing beginsのチェックした状態でclearsOnBeginEditingプロパティをfalseにするとclearsOnBeginEditingプロパティの方が優先されました

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