我有一個按鈕,如果按下,將在下拉選單中顯示專案。但我不確定按下按鈕后如何顯示顯示專案的選單。這是針對 macOS 應用程式的。
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
Button {
}
label: {
Image(systemName: "bookmark.circle")
.resizable()
.frame(width:24.0, height: 24.0)
}
.buttonStyle(PlainButtonStyle())
//List items that i want to display in the dropdown menu
ForEach((1...5), id: \.self) {
Text("\($0)")
Divider()
}
}
}
uj5u.com熱心網友回復:
您可以使用Menu:
Menu {
ForEach((1...5), id: \.self) {
Text("\($0)")
Divider()
}
} label: {
Image(systemName: "bookmark.circle")
.resizable()
.frame(width:24.0, height: 24.0)
}
ContextMenu如果你想要一個右鍵選單,你也可以使用
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/437388.html
上一篇:在SWIFT中發送本地通知
