ZStack
func ZStack(
alignment: Alignment = .center,
@FastArrayBuilder<Element> children: () -> [Element]
)
ZStack arranges child elements on top of each other and acquires the size of the largest element.
var body: Layout {
ZStack {
background
label
}
}
Alignment
Control the alignment of elements within the ZStack with the alignment property. The following snippets aligns all views to the top leading corner of the ZStack.
var body: Layout {
ZStack(alignment: .topLeading) {
view1
view2
view3
}
}
Performance Considerations
ZStack measures each child element exactly once.