how can I remove default menuItem in iOS16, including "Open Link" "Add to Reading list"

Viewed 150

In a custom UITextView, I override this function:

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    return false
}

But it still shows two menuItems, "Open Link" and "Add to Reading list". I just want to show one "copy" item.

Image showing an iOS popover

1 Answers

implement the method of UITextViewDelegate below this answer,retun an empty UIMenu that will disable all edit menu, you can try to only add the copy menu.

- (UIMenu *)textView:(UITextView *)textView editMenuForTextInRange:(NSRange)range suggestedActions:(NSArray<UIMenuElement *> *)suggestedActions  API_AVAILABLE(ios(16.0)) {
    return [UIMenu menuWithChildren:@[]];
}
Related