0

I've encountered the following issue with a .toolbar in NavigationView. It seems Spacer() doesn't work properly there. Here's a screenshot Issue

And here's the code

NavigationView {
        ...
        .toolbar {
            // bottom
            ToolbarItemGroup(placement: .bottomBar) {
                HStack {
                    NavigationLink {
                        ...SomeView...
                    } label: {
                        VStack {
                            Image(systemName: "person.circle.fill")
                            Text("Contacts")
                        }
                    }.padding()
                    Spacer()
                    NavigationLink {
                        ...SomeView...
                    } label: {
                        VStack {
                            Image(systemName: "message.fill")
                            Text("Chats")
                        }
                    }.padding()
                    Spacer()
                    NavigationLink {
                        ...SomeView...
                    } label: {
                        VStack {
                            Image(systemName: "pencil.circle")
                            Text("Settings")
                        }
                    }.padding()
                }
                .font(.caption)
                .foregroundColor(.gray)
            }
        }

Interestingly enough, it start working when I'm switching to another view (using NavigationLink), and then go back.

Another note that it shown correctly in preview in xcode, but behave differently on the phone (iPhone 12, iOS 15.4)

  • Did you try remove all ``Spacer()`` because you already have ``HStack`` handle list button – Thang Phi Sep 15 '22 at 05:56
  • @bewithyou I did, it becomes more tight on the preview, but nothing changes when reviewing on the phone, it's still left-aligned – Ilya Zakharov Sep 15 '22 at 06:04
  • Did you checked [this](https://stackoverflow.com/questions/62690819/how-does-one-use-swiftuis-toolbaritemgroup) ? – Ptit Xav Sep 15 '22 at 16:02

0 Answers0