background(_:in:fillStyle:)
Sets the view’s background to an insettable shape filled with a style.
Declaration
nonisolated func background<S, T>(_ style: S, in shape: T, fillStyle: FillStyle = FillStyle()) -> some View where S : ShapeStyle, T : InsettableShape
Parameters
- style:
A Shapestyle that SwiftUI uses to the fill the shape that you specify.
- shape:
An instance of a type that conforms to Insettableshape that SwiftUI draws behind the view.
- fillStyle:
The Fillstyle to use when drawing the shape. The default style uses the nonzero winding number rule and antialiasing.
Return Value
A view with the specified insettable shape drawn behind it.
Discussion
Use this modifier to layer a type that conforms to the InsettableShape protocol — like a Rectangle, Circle, or Capsule — behind a view. Specify the ShapeStyle that’s used to fill the shape. For example, you can place a RoundedRectangle behind a Label:
Label("Flag", systemImage: "flag.fill")
.padding()
.background(.teal, in: RoundedRectangle(cornerRadius: 8))The teal color fills the shape:
[Image]
This modifier is a convenience method for placing a single shape behind a view. To create a background with other View types — or with a stack of views — use background(alignment:content:) instead. To add a ShapeStyle as a background, use background(_:ignoresSafeAreaEdges:).
See Also
Layering views
Adding a background to your viewZStackzIndex(_:)background(alignment:content:)background(_:ignoresSafeAreaEdges:)background(ignoresSafeAreaEdges:)background(in:fillStyle:)overlay(alignment:content:)overlay(_:ignoresSafeAreaEdges:)overlay(_:in:fillStyle:)backgroundMaterialcontainerBackground(_:for:)containerBackground(for:alignment:content:)ContainerBackgroundPlacement