- 自定义 KXTestFild 类,重载deleteBackward方法,设置代理方法
protocol KXTextFieldDelegate: NSObjectProtocol {
func KXTextFieldDeleteBackward(_ textField: UITextField)
}
class KXTestFild: UITextField{
weak var KXTextFieldDelegate:YNTextFieldDelegate?
override func deleteBackward() {
super.deleteBackward()
if KXTextFieldDelegate != nil {
KXTextFieldDelegate?.KXTextFieldDeleteBackward(self)
}
}
}
func KXTextFieldDeleteBackward(_ textField: UITextField) {
if textField.text == "" {
/// 输入框删除到没有字符串时的操作
}
}
|
请发表评论