UITextField
conforms to UITextInput
protocol which in terms inherits from UIKeyInput
protocol.
UIKeyInput
protocol has func deleteBackward()
function which is called when user press delete button on the keyboard.
Create a custom subclass that inherits from UITextField
and do your work inside that function. May be notify your event handler through your custom delegate or something.
class YourCustomTextField: UITextField {
override func deleteBackward() {
super.deleteBackward()
// do your work here
}
}
Remember to call super.deleteBackward()
so that it will delete a single character or selected range of characters when user tap delete button. If you didn't call, the text wont change when user taps the delete button.