将光标向后移动,以快速删除形式一个文本字段
我已经使用这些代码将光标从一个UITextField移到另一个UITextField
tField1 -> tField2 -> tField3 -> tField4
但我想在删除textField时反向移动
tField4(deleted)-> tField3(move cursor without clear text)
tField3(deletd)-> tField2(move cursor without clear text)
等等...当我使用becomeFirstResponder()它清除文本
override func viewDidLoad() {
super.viewDidLoad()
tField1.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
tField2.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
tField3.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
tField4.addTarget(self, action: #selector(self.textFieldDidChange(textField:)), for: UIControlEvents.editingChanged)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tField1.becomeFirstResponder()
}
@objc func textFieldDidChange(textField: UITextField) {
let text = textField.text
if text?.utf16.count == 1{
switch textField{
case tField1:
tField2.becomeFirstResponder()
case tField2:
tField3.becomeFirstResponder()
case tField3:
tField4.becomeFirstResponder()
case tField4:
tField1.becomeFirstResponder()
default: break
}
}
}
链接地址: http://www.djcxy.com/p/73509.html
上一篇: Move cursor backward on deleting form one textfield to another in swift
下一篇: How to dismiss keyboard when touching anywhere outside UITextField (in swift)?