A menu element that performs its action in a block.
SDKs
- iOS 13.0+
- Mac Catalyst 13.0+
- tvOS 13.0+
Framework
- UIKit
Declaration
@interface UIAction : UIMenu Element
Overview
Create a UIAction
object when you want a menu element that performs its action in a closure.
Adds an action-based menu to the File menu
// Create a closure-based action to use as a menu element.
let refreshAction = UIAction(title: "Refresh") { (action) in
print("Refresh the data.")
}
// 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 refreshMenuItem = UIMenu(title: "", options: .displayInline, children: [refreshAction])
// Insert the menu into the File menu before the Close menu.
builder.insertSibling(refreshMenuItem, beforeMenu: .close)