I want to disable autofill feature from textfield’s action. I added image.
Autofill is coming directly. Event I try to disable Paste action with like this, I can disable Paste action, it works but Autofill still shown.
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.paste(_:)) {
return false
}
return super.canPerformAction(action, withSender: sender)
}
How can I disable “AutoFill” feature from textfield?
0
You can use TextField’s shouldChangeCharactersIn function. Here is the code example:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let numericSet = CharacterSet.decimalDigits
if let _ = string.rangeOfCharacter(from: numericSet.inverted) {
// If the condition true that means string includes non-numeric character(s). So need to return false
return false
}
return true
}
This function prevents non-numeric characters from being entered into the text field.
3