3
votes

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

How to do that ?

Thanks.

2

2 Answers

8
votes

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];
    }
}
0
votes
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.