Override "Look Up" menu item on iOS

330 views Asked by At

When you select text in iOS one of the menu items is called "Look Up".

Is it possible to override this behavior and display your own view controller?

enter image description here

1

There are 1 answers

0
pkamb On

You can override these commands and provide custom controls via the UIMenuController and UIMenuItem classes:

  • https://developer.apple.com/documentation/uikit/uimenucontroller
  • https://nshipster.com/uimenucontroller/

    UIMenuItem

    With iOS 3.2, developers could now add their own commands to the menu controller. As yet unmentioned, but familiar commands like “Define” or spell check suggestions take advantage of this.

    UIMenuController has a menuItems property, which is an NSArray of UIMenuItem objects. Each UIMenuItem object has a title and action. In order to have a menu item command display in a menu controller, the responder must implement the corresponding selector.