1

I'd like to achieve something similar in SwiftUI to what is described in Apple's Human Interface Guidelines about toolbars.

enter image description here

I tried using .toolbar { } but items are too small and NavigationLink doesn't change the selected View. I tried setting ExpandedWindowToolbarStyle() on WindowGroup.

Code:

NavigationView { }
        .toolbar {
            ToolbarItem(placement: ToolbarItemPlacement.automatic) {
                HStack {
                    Text("")
                    NavigationLink(
                        destination: getDestination(forOption: Option.home)) {
                        VStack {
                            Image(systemName: Option.home.iconName)

                            Text("test")
                        }
                        .frame(height: 50)


                    }
                }

            }
        }

current state:

enter image description here

1 Answer 1

2

You can use a customizable toolbar and labels.

enter image description here

        .toolbar(id: "Main") {
            ToolbarItem(id: "Sidebar") {
                Button(action: {}) {
                    Label("Sidebar", systemImage: "sidebar.right")
                }
            }
        }

Also it might be possible to use TitleAndIconLabelStyle with MacOS 11.3. I haven't tried it yet.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but it doesn't provide a solution for embedding the navigation links in toolbar items. I tried a few different solution but with no success
@mikro098 A NavigationLink is just not meant to be within a toolbar. It’s meant for NavigationView.
Super helpful @Stephan Michels! Please notice that giving the toolbar an id is necessary for it to be configurable by the user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.