How do you programatically select all the text in a Swift text field?
var textField:UITextField = UITextField() textField.frame = CGRectMake(2, 25, 200, 20) textField.text = "hello" textField.font = UIFont(name: "Verdana", size: 12) textField.textColor = UIColor.blackColor() textField.backgroundColor = UIColor.whiteColor()
Or at least make the text immediately editable?
Thanks
Andrew
It works in the same way like in Objective-C:
textField.becomeFirstResponder() textField.selectedTextRange = textField.textRange(from: textField.beginningOfDocument, to: textField.endOfDocument)
textField.becomeFirstResponder() textField.selectAll(nil)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With