Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a menu to the Navigationbar?

Tags:

swiftui

menu

I want to create menu like in Files App. I added buttons but I dont know how can I create menu like this in SwiftUI. Do you have any id?

enter image description here

.navigationBarItems(trailing:  Button(action: {  }) {
                                    Image(systemName: "ellipsis.circle")
                                        .font(.system(size: 21))
})
like image 294
Robert Avatar asked Sep 06 '25 00:09

Robert


1 Answers

In SwiftUI 2 you can use a Menu placed in a Toolbar:

struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("Test")
                .toolbar {
                    ToolbarItem(placement: .navigationBarTrailing) {
                        Menu(content: {
                            Button("Option 1", action: {})
                            Button("Option 2", action: {})
                            Button("Option 3", action: {})
                        }) {
                            Image(systemName: "ellipsis.circle")
                                .font(.system(size: 21))
                        }
                    }
                }
        }
    }
}
like image 129
pawello2222 Avatar answered Sep 07 '25 19:09

pawello2222