跳转至
Structure

ZStack

A view that arranges children on top of each other.

Declaration

@frozen struct ZStack<Content> : View where Content : View

Overview

ZStack arranges views "into" and "out of" the screen. The result is vies stacked on top of each other.

struct ExampleView: View {
    var body: some View {
        ZStack {
            Text("I am obscured by clouds")
            Text("☁️☁️☁️☁️")
        }
    }
}
A screenshot displaying two text views in a ZStack; the bottom layer is text that reads "I am obscured by clouds," where the top layer is a set of cloud emojis that obscure the text.

Learn more about the properties of each alignment choice via the Alignment struct.

ZStack uses a ViewBuilder to construct the content.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Type Alias

Body The type of view representing the body of this view.


Initializer

init(alignment:content:) Creates a ZStack with the given alignment.