Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable UITextField double tap or long press in Swift iOS? [duplicate]

Tags:

ios

swift

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.

like image 278
Pranit Avatar asked Mar 10 '23 15:03

Pranit


1 Answers

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)
    }
like image 187
Sivajee Battina Avatar answered Mar 12 '23 05:03

Sivajee Battina