<!--
{
  "availability" : [
    "iOS: 16.0.0 - 27.0.0",
    "iPadOS: 16.0.0 - 27.0.0",
    "macCatalyst: 16.0.0 - 27.0.0",
    "macOS: 13.0.0 - 27.0.0",
    "tvOS: 16.0.0 - 27.0.0",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/toolbarBackground(_:for:)-7lv0f",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE17toolbarBackground_3forQrAA10VisibilityO_AA16ToolbarPlacementVdtF"
  },
  "title" : "toolbarBackground(_:for:)"
}
-->

# toolbarBackground(_:for:)

Specifies the preferred visibility of backgrounds on a bar managed by
SwiftUI.

```
nonisolated func toolbarBackground(_ visibility: Visibility, for bars: ToolbarPlacement...) -> some View
```

## Parameters

`visibility`

The preferred visibility of the background of the bar.

`bars`

The bars to update the color scheme of or
`ToolbarPlacement/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.

In iOS, a value of `ToolbarPlacement/automatic` makes the visibility
of a tab bar or navigation bar background depend on where a `List` or
`ScrollView` settles. For example, when aligned to the bottom edge of
of a scroll view’s content, the background of a tab bar becomes
transparent.

Specify a value of `Visibility/visible` to ensure that the
background of a bar remains visible regardless of where any scroll
view or list stops scrolling.

This example shows a view that prefers to always have the tab bar
visible when the middle tab is selected:

```
TabView {
    FirstTab()
    MiddleTab()
        .toolbarBackground(.visible, for: .tabBar)
    LastTab()
}
```

You can provide multiple placements to customize multiple bars
at once, as in the following example:

```
TabView {
    NavigationView {
        ContentView()
            .toolbarBackground(
                .visible, for: .navigationBar, .tabBar)
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)