The singleton UIMenuController instance presents the menu interface for the Cut, Copy, Paste, Select, Select All, and Delete commands.


This menu is referred to as the editing menu. When you make this menu visible, UIMenuController positions it relative to a target rectangle on the screen; this rectangle usually defines a selection. The menu appears above the target rectangle or, if there is not enough space for it, below it. The menu’s pointer is placed at the center of the top or bottom of the target rectangle, as appropriate. Be sure to set the tracking rectangle before you make the menu visible. You are also responsible for detecting, tracking, and displaying selections.

The UIResponderStandardEditActions informal protocol declares methods that are invoked when the user taps a menu command. The canPerformAction(_:withSender:) method of UIResponder is also related to the editing menu. A responder implements this method to enable and disable commands of the editing menu just before the menu is displayed. You can force this updating of menu commands’ enabled state by calling the update() method.

You can also provide your own menu items via the menuItems property. When you modify the menu items, you can use the update() method to force the menu to update its display.


Getting the Menu Controller Instance

class var shared: UIMenuController

Returns the menu controller.

Showing and Hiding the Menu

var isMenuVisible: Bool

The visibility of the editing menu.

func setMenuVisible(Bool, animated: Bool)

Shows or hides the editing menu, optionally animating the action.

Positioning the Menu

func setTargetRect(CGRect, in: UIView)

Sets the area in a view above or below which the editing menu is positioned.

var menuFrame: CGRect

Returns the frame of the editing menu.

var arrowDirection: UIMenuControllerArrowDirection

The direction the arrow of the editing menu is pointing.

Updating the Menu

func update()

Updates the appearance and enabled state of menu commands.

Customizing Menu Items

var menuItems: [UIMenuItem]?

The custom menu items for the editing menu.


static let UIMenuControllerWillShowMenu: NSNotification.Name

Posted by the menu controller just before it shows the menu.

static let UIMenuControllerDidShowMenu: NSNotification.Name

Posted by the menu controller just after it shows the menu.

static let UIMenuControllerWillHideMenu: NSNotification.Name

Posted by the menu controller just before it hides the menu.

static let UIMenuControllerDidHideMenu: NSNotification.Name

Posted by the menu controller just after it hides the menu.

static let UIMenuControllerMenuFrameDidChange: NSNotification.Name

Posted when the frame of a visible menu changes.


Inherits From

Conforms To