1

I want to show two navigationBarItems in my app, so I added two navigationBarItems but only one is shown.

Here is my code

struct ContentView: View {

    var body: some View {
        NavigationView{
            VStack{
                Text("Something")
            }.navigationBarTitle("Title", displayMode: .inline)
            .navigationBarItems(leading: Text("Text1"))
            .navigationBarItems(trailing:Text("Text2"))
        }
    }
}

And this is how looks like in Xcode enter image description here

2 Answers 2

3

Update the code that sets the navigationBarItems to this:

.navigationBarItems(leading: Text("Text1"), trailing: Text("Text2"))
2

You can also set multiple navigation items as a HStack:

.navigationBarItems(trailing: HStack {
    Button("Action 1") { print("Action 1") }
    Button("Action 2") { print("Action 2") }
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.