Custom UITextField to Disallow All Actions like Copy Paste etc

suggest change

If we want to disable all the actions like Copy, Paste, Replace, Select, etc from UITextField then we can use following custom text field:

class CustomTextField: UITextField {

var enableLongPressActions = false

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)!
}

override init(frame: CGRect) {
    super.init(frame: frame)
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    return enableLongPressActions
}
}

Using enableLongPressActions property, we can enable all actions any time later, if needed.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents