I want to remove some default UIMenuItem objects like "Cut", "Copy", etc, from the UIMenuController.
How to do that ?
Thanks.
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];
}
}
class TextView: UITextView {
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(copy(_:)){
return true
}
else{
return false
}
}
}
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.