.background(style?: Style)
.background(content: Component)
.background(props: { alignment: Alignment }, content: Component)
Overload 1: Style background
Overload 2: Component background
A component to render behind this component.
Overload 3: Component background with alignment
How to position the background component within this component’s bounds. See Alignment.
A component to render behind this component, positioned according to alignment.
Support
Usage
Color background
Text("Hello")
.padding(16)
.background(Color("blue"))
Gradient background
Text("Gradient")
.padding(16)
.background(LinearGradient({
colors: ["purple", "blue"],
startPoint: "leading",
endPoint: "trailing"
}))
Material background
Text("Frosted")
.padding(16)
.background(Material("thin"))
Component background
Text("Labeled")
.padding(16)
.background(
RoundedRectangle(12)
.foregroundStyle(Color("blue"))
)
Component background with alignment
Text("Badge")
.padding(16)
.background(
{ alignment: "topTrailing" },
Circle()
.frame({ width: 12, height: 12 })
.foregroundStyle(Color("red"))
)
See Also