Contents

ContentToolbarPlacement

A region of the interface that hosts its own toolbar content.

Declaration

struct ContentToolbarPlacement

Overview

Some containers draw a bar that belongs to the container as a whole rather than to the view currently on screen, such as the sidebar of a TabView that uses the sidebarAdaptable style. Pass a value of this type to contentToolbar(for:content:) to put items in one of those bars.

The following example adds a button to the sidebar of a tab view, where it stays put as someone moves between tabs:

TabView {
    Tab("Lights", systemImage: "lightbulb") {
        LightsView()
    }

    Tab("Locks", systemImage: "lock") {
        LocksView()
    }
}
.tabViewStyle(.sidebarAdaptable)
.contentToolbar(for: .tabViewSidebar) {
    ToolbarItem {
        DisconnectDevicesButton()
    }
}

Each placement accepts only some ToolbarItemPlacement values. Check the documentation of the placement you use before you rely on a position.

Topics

Type Properties

See Also

Setting toolbar visibility