A single component or array of components to layer. The last child renders on top.
Configuration options for the stack.
Layers children on top of each other in a back-to-front stack.
ZStack(children: Component): Component;
ZStack(children: Component[]): Component;
ZStack(props: { alignment?: Alignment }, children: Component[]): Component;
ZStack([
Image({ url: "background.jpg" }),
Text("Overlay text")
.foregroundStyle(Color("white"))
.font("title")
])
ZStack({ alignment: "bottomTrailing" }, [
Image({ url: "photo.jpg" })
.frame({ width: 200, height: 200 }),
Text("Caption")
.padding(8)
.background(Color("black").opacity(0.6))
.foregroundStyle(Color("white"))
.cornerRadius(4)
])
ZStack({ alignment: "topTrailing" }, [
Image({ systemName: "bell" })
.font("title"),
Circle()
.fill(Color("red"))
.frame({ width: 12, height: 12 })
])
ZStack([
Rectangle().fill(Color("blue")),
Circle()
.fill(Color("white").opacity(0.3))
.frame({ width: 150, height: 150 }),
Text("Center")
.foregroundStyle(Color("white"))
])
.frame({ width: 200, height: 200 })