contentToolbar(for:content:)
Populates the toolbar of the specified content view type with the views you provide.
Declaration
nonisolated func contentToolbar<Content>(for placement: ContentToolbarPlacement, @ContentBuilder content: () -> Content) -> some View where Content : View
Parameters
- content:
The views representing the content of the toolbar.
Discussion
Use this modifier to add toolbar content that remains consistent regardless of the content view.
Unlike the toolbar modifier, which configures the toolbar of the modified view’s container, the contentToolbar modifier configures the toolbar within the modified view’s content instead. This means that the contentToolbar modifier should generally be applied directly to a container view, instead of to the content within a container view. For example, to configure the toolbar of tab view’s sidebar, apply the contentToolbar modifier to the TabView itself, not to any of the tabs within the TabView.
The example below adds a button to the tab view sidebar.
TabView {
Tab("Home", systemImage: "house") {
HomeView()
}
Tab("Alerts", systemImage: "bell") {
AlertsView()
}
TabSection("Categories") {
Tab("Climate", systemImage: "fan") {
ClimateView()
}
Tab("Lights", systemImage: "lightbulb") {
LightsView()
}
}
}
.tabViewStyle(.sidebarAdaptable)
.contentToolbar(for: .tabViewSidebar) {
DisconnectDevicesButton()
}See Also
Toolbars
toolbar(content:)toolbar(id:content:)toolbar(_:for:)toolbar(removing:)toolbarVisibility(_:for:)toolbarBackground(_:for:)toolbarBackgroundVisibility(_:for:)toolbarItemHidden(_:)toolbarForegroundStyle(_:for:)toolbarColorScheme(_:for:)toolbarOverflowMenu(content:)toolbarRole(_:)toolbarMinimizationSafeAreaAdjustment(_:for:)toolbarMinimizeBehavior(_:for:)toolbarTitleMenu(content:)