Skip to content
Snippets Groups Projects
Commit f2f30896 authored by Zandor Smith's avatar Zandor Smith :computer:
Browse files

Add option to UITextFieldTableViewCell to select all UITextField content upon begin editing.

parent a902917a
No related branches found
Tags 1.22.0
No related merge requests found
......@@ -11,6 +11,7 @@ import UIKit
public class UITextFieldTableViewCell: UITableViewCell {
public var textField = UITextField()
public var selectAllOnBeginEditing: Bool = false
public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
......@@ -34,6 +35,7 @@ public class UITextFieldTableViewCell: UITableViewCell {
textField.textAlignment = .right
textField.borderStyle = .none
textField.frame = CGRect(x: 0, y: 0, width: 150, height: 20)
textField.delegate = self
self.selectionStyle = .none
self.accessoryView = textField
......@@ -41,5 +43,16 @@ public class UITextFieldTableViewCell: UITableViewCell {
self.layoutIfNeeded()
}
}
extension UITextFieldTableViewCell: UITextFieldDelegate {
public func textFieldDidBeginEditing(_ textField: UITextField) {
guard selectAllOnBeginEditing else {
return
}
textField.perform(#selector(textField.selectAll(_:)), with: nil, afterDelay: 0.05)
}
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment