How to remove default UIMenuItem from UIMenuController in iOS?

I want to delete some default UIMenuItem objects, such as Cut, Copy, etc. from UIMenuController.

How to do it?

Thank.

+2
source share
2 answers

Subclass: View menu (eg UIWebView, UITextView) and the override -canPerformAction:withSender:to return NOto the menu items that you do not want to display.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(copy:)) {
        return NO;
    }
    else {
        return [super canPerformAction:action withSender:sender];
    }
}
+6
source
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 Stewart said: Subclass: menu view (e.g. UITextView)

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

return false for menu items that you do not want to display.

0
source

All Articles