<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIMenu",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIMenu"
  },
  "title" : "UIMenu"
}
-->

# UIMenu

A container for grouping related menu elements in an app menu or contextual menu.

```
@MainActor class UIMenu
```

## Overview

Create [`UIMenu`](/documentation/UIKit/UIMenu) objects and use them to construct the menus and submenus your app displays. You provide menus for your app when it runs on macOS, and key command elements in those menus also appear in the discoverability HUD on iPad when someone presses the Command key. You also use menus to display contextual actions in response to specific interactions with one of your views. Every menu has a title, an optional image, and an optional set of child elements. When someone selects an element from the menu, the system executes the code you provide. The code sample below illustrates adding a menu group that contains two menu elements — New and Open — to the File menu.

```swift
// Ensure that the builder is modifying the menu bar system.
guard builder.system == UIMenuSystem.main else { return }

let newDocument = UIKeyCommand(title: "New",
                               action: #selector(newDocument(_:)),
                               input: "n",
                               modifierFlags: .command)

let openDocument = UIKeyCommand(title: "Open...",
                                action: #selector(openDocument(_:)),
                                input: "o",
                                modifierFlags: .command)

// Use the .displayInline option to avoid displaying the menu as a submenu,
// and to separate it from the other menu elements using a line separator.
let newMenu = UIMenu(title: "", options: .displayInline, children: [newDocument, openDocument])

// Insert the menu item at the top of the File menu.
builder.insertChild(newMenu, atStartOfMenu: .file)
```

For examples of how you use [`UIMenu`](/documentation/UIKit/UIMenu), see [Adding menus and shortcuts to the menu bar and user interface](/documentation/UIKit/adding-menus-and-shortcuts-to-the-menu-bar-and-user-interface).

## Topics

### Creating a menu object

[`init(title:image:identifier:options:children:)`](/documentation/UIKit/UIMenu/init(title:image:identifier:options:children:))

Creates a new menu with the specified values.

[`init(title:subtitle:image:identifier:options:children:)`](/documentation/UIKit/UIMenu/init(title:subtitle:image:identifier:options:children:))

Creates a new menu with the specified title, subtitle, image, identifier, menu options, and child elements.

[`init(title:subtitle:image:identifier:options:preferredElementSize:children:)`](/documentation/UIKit/UIMenu/init(title:subtitle:image:identifier:options:preferredElementSize:children:))

Creates a new menu with the specified title, subtitle, image, identifier, menu options, element size, and child elements.

[`+  menuWithChildren:`](/documentation/UIKit/UIMenu/menuWithChildren:)

Creates a new menu with the specified child elements.

[`+  menuWithTitle:children:`](/documentation/UIKit/UIMenu/menuWithTitle:children:)

Creates a menu with the specified title and child menu elements.

[`+  menuWithTitle:image:identifier:options:children:`](/documentation/UIKit/UIMenu/menuWithTitle:image:identifier:options:children:)

Creates a new menu with the specified values.

[`Identifier`](/documentation/UIKit/UIMenu/Identifier-swift.struct)

Constants you use to identify an app’s standard menus.

[`Options`](/documentation/UIKit/UIMenu/Options-swift.struct)

Options you use to configure a menu’s appearance.

[`-  initWithCoder:`](/documentation/UIKit/UIMenu/init(coder:))

Creates a menu from data in an unarchiver.

### Accessing child elements

[`children`](/documentation/UIKit/UIMenu/children)

The contents of the menu.

[`-  menuByReplacingChildren:`](/documentation/UIKit/UIMenu/replacingChildren(_:))

Creates a new menu with the same configuration as the current menu, but with a new set of child elements.

### Accessing selected elements

[`selectedElements`](/documentation/UIKit/UIMenu/selectedElements)

The elements in the menu and its sub-menus that are in the on state.

### Getting menu details

[`identifier`](/documentation/UIKit/UIMenu/identifier-swift.property)

The unique identifier for the current menu.

[`options`](/documentation/UIKit/UIMenu/options-swift.property)

The configuration options for the current menu.

### Specifying size of menu elements

[`preferredElementSize`](/documentation/UIKit/UIMenu/preferredElementSize)

The size of the menu’s child elements.

[`ElementSize`](/documentation/UIKit/UIMenu/ElementSize)

Constants that determine the size of an element in a menu.

### Customizing menu display

[`displayPreferences`](/documentation/UIKit/UIMenu/displayPreferences)

An object that configures how UIKit displays the menu.

[`UIMenuDisplayPreferences`](/documentation/UIKit/UIMenuDisplayPreferences)

An object that contains information for configuring a menu’s display.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`UIAccessibilityIdentification`](/documentation/UIKit/UIAccessibilityIdentification)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`NSCopying`](/documentation/Foundation/NSCopying)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`NSSecureCoding`](/documentation/Foundation/NSSecureCoding)

[`Equatable`](/documentation/Swift/Equatable)

[`NSCoding`](/documentation/Foundation/NSCoding)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

### Inherits From

[`UIMenuElement`](/documentation/UIKit/UIMenuElement)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)