backgroundStyle(_:)
Sets the specified style to render backgrounds within the view.
Declaration
nonisolated func backgroundStyle<S>(_ style: S) -> some View where S : ShapeStyle
Discussion
The following example uses this modifier to set the backgroundStyle environment value to a blue color that includes a subtle 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)[Image]
To restore the default background style, set the backgroundStyle environment value to nil using the environment(_:_:) modifer:
.environment(\.backgroundStyle, nil)