How to create a custom UIMenuController with only individual elements other than standard?

I have a requirement to display menu items in uiwebview whenever a user selects any text. enter image description here

I tried

let highlightMenuItem = UIMenuItem(title: "Highlight", action: #selector(ViewController.hightlight))

UIMenuController.sharedMenuController().menuItems = [highlightMenuItem]

but this only adds more to the default menu item. like this

enter image description here enter image description here

Is there any way to achieve this only with the menu items "Copy", "Select" and "Note"?

+4
source share
1 answer

UIWebView canPerformAction (Swift 3). , , false , .

:

class EditedUIMenuWebView: UIWebView {

  override func canPerformAction(_ action: Selector, withSender sender: AnyObject?) -> Bool {
    if action == #selector(cut(_:)) {
      return false
    }
    if action == #selector(paste(_:)) {
      return false
    }
    if action == #selector(select(_:)) {
      return false
    }
    if action == #selector(selectAll(_:)) {
      return false
    }
    ...

    return super.canPerformAction(action, withSender: sender)
  }

}

, , !

. , false canPerformAction true , :

override func canPerformAction(_ action: Selector, withSender sender: AnyObject?) -> Bool {
   if action == #selector(copy(_:)) || action == #selector(customMethod(_:)) {
     return true
   }
   ...
   return false
 }
+10

All Articles