3

I want to remove some default UIMenuItem objects like "Cut", "Copy", etc, from the UIMenuController.

How to do that ?

Thanks.

user403015
  • 7,209
  • 19
  • 66
  • 100

2 Answers2

8

Subclass the view that's presenting the menu (eg. UIWebView, UITextView) and override -canPerformAction:withSender: to return NO for the menu items you don't want to appear.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:)) {
        return NO;
    }
    else {
        return [super canPerformAction:action withSender:sender];
    }
}
Peter Stuart
  • 126
  • 6
  • How'd you get rid of Paste option? I tried the same with Paste, but it's showing up. I guess, it's because the Paste board has some content already.. – Mohammad Abdurraafay Oct 23 '12 at 08:14
0
class TextView: UITextView {
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        if action == #selector(copy(_:)){
            return true
        }
        else{
            return false
        }
    }
}

In Swift 4 ,

0

As Peter Stuart said: Subclass the view that's presenting the menu (eg. UITextView)

then override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool

return false for the menu items you don't want to appear.

dengApro
  • 3,848
  • 2
  • 27
  • 41