Contents

toolbarVerticalCompressionBehavior(_:)

Sets how bars should compress when different types of toolbars are hosted together and space is constrained.

Declaration

nonisolated func toolbarVerticalCompressionBehavior(_ behavior: ToolbarVerticalCompressionBehavior) -> some View

Discussion

For example, a productivity-focused app like Files could ensure its toolbar items are preferred over the tab bar:

struct ContentView: View {
    var body: some View {
        TabView {
            Tab("Recents") {
                NavigationStack {
                    RootView()
                        .toolbar {
                            Button("Up", systemImage: "chevron.up") {
                            }
                            Button("Down", systemImage: "chevron.down") {
                            }
                        }
                        .toolbarVerticalCompressionBehavior(.prefersToolbarItems)
                }
            }
        }
    }
}

See Also

Configuring vertical toolbar behavior