Member-only story

UITextField to disallow all actions like copy, paste etc.

Mr.Javed Multani
1 min readOct 3, 2020

--

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 = falserequired 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.

--

--

Mr.Javed Multani
Mr.Javed Multani

Written by Mr.Javed Multani

Software Engineer | Certified ScrumMaster® (CSM) | UX Researcher | Youtuber | Tech Writer

No responses yet