backgroundStyle

Sets the specified style to render backgrounds within the view.

View ModifieriOS 16.0+macOS 13.0+tvOS 16.0+watchOS 9.0+backgroundStyle(_:) in SwiftUI

Declaration

React
compose().backgroundStyle(style: SwiftUI.ShapeStyle)
Swift
nonisolated func backgroundStyle<S>(
    _ style: S
) -> some View
where S : ShapeStyle

Parameters

Discussion

The following example uses this modifier to set the EnvironmentValues.backgroundStyle environment value to a ShapeStyle.blue color that includes a subtle Color.gradient. SwiftUI fills the Circle shape that acts as a background element with this style:

Image(systemName: "swift")
    .padding()
    .background(in: Circle())
    .backgroundStyle(.blue.gradient)

To restore the default background style, set the EnvironmentValues.backgroundStyle environment value to nil using the View.environment(_:_:) modifer:

.environment(\.backgroundStyle, nil)

See also

More in Styles.