hidden(_:)
Hides a toolbar item within its toolbar.
Declaration
nonisolated func hidden(_ hidden: Bool = true) -> some CustomizableToolbarContent
Parameters
- hidden:
Whether the toolbar item is hidden.
Discussion
Use this modifier to conditionally display a toolbar item in the toolbar. On macOS, hidden items will be displayed during user customization.
The following example hides a downloads button when there are no downloads, but it is displayed during customization.
struct ContentView {
@State private var showDownloads = false
var body: some View {
BrowserView()
.toolbar(id: "browserToolbar") {
ToolbarItem(id: "downloads") {
DownloadsButton()
}
.hidden(!showDownloads)
}
}
}