toolbar(_:for:)
Specifies the visibility of a bar managed by SwiftUI.
Declaration
nonisolated func toolbar(_ visibility: Visibility, for bars: ToolbarPlacement...) -> some View
Parameters
- visibility:
The preferred visibility of the bar.
- bars:
The bars to update the visibility of or Automatic if empty.
Discussion
The preferred visibility 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.
This examples shows a view that hides the navigation bar on iOS, or the window toolbar items on macOS.
NavigationView {
ContentView()
.toolbar(.hidden)
}To hide the entire titlebar on macOS, use this modifier with windowToolbar placement.
NavigationView {
ContentView()
.toolbar(.hidden, for: .windowToolbar)
}You can provide multiple ToolbarPlacement instances to hide multiple bars at once.
TabView {
NavigationView {
ContentView()
.toolbar(
.hidden, for: .navigationBar, .tabBar)
}
}Depending on the specified bars, the requested visibility may not be able to be fulfilled.