0

I want to remove the option "Paste" from the selector

I've tried the code below but it adds other selections to the selector and the paste option is still there, it just disables the functionality

override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
    if action == "paste:" {
        return false
    }
    return true
  }

I want to remove Paste all together so the user doesn't even have the option to see it or click it

enter image description here

SlopTonio
  • 1,105
  • 1
  • 16
  • 39

2 Answers2

0

Have a look at UIMenuController You should be able to use var menuItems: [AnyObject]?

to set up your own object.

It is not a simple switch on or off the existing buttons, looks like you have to provide your own.

iCyberPaul
  • 650
  • 4
  • 15
0

try this :

Step 1: You need to create another class which extends the UITextField. In this example, I made my CustomizedUITextField.

import UIKit

class CustomTextField: UITextField {
    override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
        if action == "paste:" {
            return false
        }

        return super.canPerformAction(action, withSender: sender)
    }
}
iAnurag
  • 9,286
  • 3
  • 31
  • 48