Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the paste option from menu in UITextField in Swift 3.0?

I tried with every answer posted for this similar question, but it is not working in Swift 3.

  override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
   if action == #selector(paste(_:)) {
        return false
    }
   return super.canPerformAction(action, withSender: sender)
}

Thanks

like image 699
Nisha Nair Avatar asked Feb 05 '23 09:02

Nisha Nair


2 Answers

In case anyone looking for swift 4.2

 override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        OperationQueue.main.addOperation {
            UIMenuController.shared.setMenuVisible(false, animated: false)
        }

        return super.canPerformAction(action, withSender: sender)
    }
like image 77
channu Avatar answered Feb 08 '23 00:02

channu


This works!

 override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {

    NSOperationQueue.mainQueue().addOperationWithBlock {
        UIMenuController.sharedMenuController().setMenuVisible(false, animated: false)
    }

    return super.canPerformAction(action, withSender: sender)
}
like image 22
Nisha Nair Avatar answered Feb 08 '23 00:02

Nisha Nair