Home > Blockchain >  How to display dropdown menu in macOS swiftUI
How to display dropdown menu in macOS swiftUI

Time:03-03

i have a button if pressed, will show items in a dropdown menu. But i'm not sure how to display a menu showing the itmes after pressing the button. This is for a macOS app.

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()
        }         
   }       
}
   

CodePudding user response:

You can use Menu:

Menu {
    ForEach((1...5), id: \.self) {
        Text("\($0)")
        Divider()
    }
} label: {
    Image(systemName: "bookmark.circle")
        .resizable()
        .frame(width:24.0, height: 24.0)
}

You can also use ContextMenu if you want a right-click menu

  • Related