The UITextField's Select, SelectAll, Cut, Copy functionality is shown by default, When I long press or Double Tap on the TextField. I do not require this all features. Please tell me how to disable long press or double tap gesture functionality.
Asked
Active
Viewed 6,117 times
2 Answers
4
Following code will disable those options:
You have to subclass the UITextField
and try to use this code to disable/hide caret and input (copy/paste)
override func caretRectForPosition(position: UITextPosition!) -> CGRect {
return CGRect.zeroRect
}
override func selectionRectsForRange(range: UITextRange) -> [AnyObject] {
return []
}
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
// Disable copy, select all, paste
if action == Selector("copy:") || action == Selector("selectAll:") || action == Selector("paste:") {
return false
}
// Default
return super.canPerformAction(action, withSender: sender)
}

Sivajee Battina
- 4,124
- 2
- 22
- 45
3
Here is the swift 3.0 answer,
please try this,
override func canPerformAction(_ action: Selector, withSender sender: Any) -> Bool {
UIMenuController.shared.menuVisible = false
//do not display the menu
self.resignFirstResponder()
//do not allow the user to selected anything
return false
}
Hope this will help you.

KAR
- 3,303
- 3
- 27
- 50