Return Value 戻り値
A view with the specified shape drawn behind it.
Availability 有効性
Technology
A view with the specified shape drawn behind it.
shape
An instance of a type that conforms to Shape
that SwiftUI draws behind the view using the background
shape style.
fillStyle
The Fill
to use when drawing the shape. The default style uses the nonzero winding number rule and antialiasing.
This modifier behaves like background(_:
, except that it always uses the background
shape style to fill the specified shape. For example, you can create a Path
that outlines a trapezoid:
let trapezoid = Path { path in
path.move(to: .zero)
path.addLine(to: CGPoint(x: 90, y: 0))
path.addLine(to: CGPoint(x: 80, y: 50))
path.addLine(to: CGPoint(x: 10, y: 50))
}
Then you can use that shape as a background for a Label
:
ZStack {
Color.teal
Label("Flag", systemImage: "flag.fill")
.padding()
.background(in: trapezoid)
}
Without the background modifier, the fill color shows through the label. With the modifier, the label’s text and icon appear backed by a shape filled with a color that’s appropriate for light or dark appearance:
To create a background with other View
types — or with a stack of views — use background(alignment:
instead. To add a Shape
as a background, use background(_:
.