Declaration
compose().toolbarColorScheme(
colorScheme: SwiftUI.ColorScheme | null,
options: {
for: SwiftUI.ToolbarPlacement[];
}
)nonisolated func toolbarColorScheme(
_ colorScheme: ColorScheme?,
for bars: ToolbarPlacement...
) -> some ViewParameters
colorScheme*SwiftUI.ColorScheme | nullThe preferred color scheme of the background of the bar.
options.for*SwiftUI.ToolbarPlacement[]
Discussion
The preferred color scheme flows up to the nearest container
that renders a bar. This could be a NavigationView or TabView
in iOS, or the root view of a WindowGroup in macOS. Pass in a value
of nil to match the current system's color scheme.
This examples shows a view that renders the navigation bar with a blue background and dark color scheme:
TabView {
NavigationView {
ContentView()
.toolbarBackground(.blue)
.toolbarColorScheme(.dark)
}
// other tabs...
}You can provide multiple ToolbarPlacement instances to customize
multiple bars at once.
TabView {
NavigationView {
ContentView()
.toolbarBackground(
.blue, for: .navigationBar, .tabBar)
.toolbarColorScheme(
.dark, for: .navigationBar, .tabBar)
}
}Note that the provided color scheme is only respected while a background is visible in the requested bar. As the background becomes visible, the bar transitions from the color scheme of the app to the requested color scheme. You can ensure that the color scheme is always respected by specifying that the background of the bar always be visible.
NavigationView {
ContentView()
.toolbarBackground(.visible)
.toolbarColorScheme(.dark)
}Depending on the specified bars, the requested color scheme may not be able to be fullfilled.
See also
More in Navigation.
- assistiveAccessNavigationIconConfigures the view's icon for purposes of navigation.
- asyncImageURLSessionA modifier that adds a URL session for asynchronous images contained in the view to use when fetching image data.
- contentToolbarPopulates the toolbar of the specified content view type with the views you provide.
- defaultAdaptableTabBarPlacementSpecifies the default placement for the tabs in a tab view using the adaptable sidebar style.
- defaultTabBarPlacementSpecifies the preferred placement for the tabs of a TabView in the TabViewStyle.sidebarAdaptable style on platforms where the tab bar cannot adapt between different representations, and only one representation can be shown.
- navigationBarBackButtonHiddenHides the navigation bar back button for the view.
- navigationBarTitleDisplayModeConfigures the title display mode for this view.
- navigationDestinationAssociates a destination view with a presented data type for use within a navigation stack.
- navigationDocumentConfigures the view's document for purposes of navigation.
- navigationLinkIndicatorVisibilityConfigures whether navigation links show a disclosure indicator.
- navigationSplitViewColumnWidthSets a fixed, preferred width for the column containing this view.
- navigationSubtitleConfigures the view's subtitle for purposes of navigation, using a localized string resource.