Robert
Robert

Reputation: 119

How do I add a menu to the Navigationbar?

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

Upvotes: 3

Views: 1386

Answers (1)

pawello2222
pawello2222

Reputation: 54426

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

Upvotes: 7

Related Questions