Use context
instead.
ContextMenu
Deprecated 非推奨
Availability 有効性
- iOS 13.0–15.4 Deprecated
- iPadOS 13.0–15.4 Deprecated
- macOS 10.15–12.3 Deprecated
- Mac Catalyst 13.0–15.4 Deprecated
- watchOS 6.0–7.0 Deprecated
Technology
- Swift
UI
Declaration 宣言
struct ContextMenu<MenuItems> where MenuItems : View
Overview 概要
A context menu view allows you to present a situationally specific menu to the user allowing them to perform actions relevant to the current task they’re performing in your app.
You create a context menu by first defining a Context
container with the buttons that represent the actions a user can select from. Next, you add a context
view modifier to the view that enables the context menu. The context menu view modifier takes the menu items you defined above as its argument.
The example below creates a four-item context menu container used by the context menu view modifier. The Boolean value should
controls the attachment of the context menu; it is set to true
, enabling the contextual menu.
Note that it is possible to place the actions performed by the menu selection directly inside the button closures or, as shown below, to invoke them via function references.
func selectHearts() {
// Act on hearts selection.
}
func selectClubs() { ... }
func selectSpades() { ... }
func selectDiamonds() { ... }
let menuItems = ContextMenu {
Button("♥️ - Hearts", action: selectHearts)
Button("♣️ - Clubs", action: selectClubs)
Button("♠️ - Spades", action: selectSpades)
Button("♦️ - Diamonds", action: selectDiamonds)
}
struct ContextMenuMenuItems: View {
private var shouldShowMenu = true
var body: some View {
VStack {
Text("Favorite Card Suit")
.padding()
.contextMenu(shouldShowMenu ? menuItems : nil)
}
}
}
Topics 話題
Creating a Context Menu コンテキストメニューを作成する
See Also 参照
Auxiliary View Modifiers
func navigationBarTitle (Text) -> some View
func navigationBarTitle (Text, displayMode : NavigationBarItem .TitleDisplayMode ) -> some View
func navigationBarTitle (LocalizedStringKey ) -> some View
func navigationBarTitle <S>(S) -> some View
func navigationBarTitle (LocalizedStringKey , displayMode : NavigationBarItem .TitleDisplayMode ) -> some View
func navigationBarTitle <S>(S, displayMode : NavigationBarItem .TitleDisplayMode ) -> some View
func navigationBarItems <L>(leading: L) -> some View
func navigationBarItems <L, T>(leading: L, trailing: T) -> some View
func navigationBarItems <T>(trailing: T) -> some View
func contextMenu <MenuItems >(ContextMenu <MenuItems >?) -> some View