SwiftUI: Solid filled background.

Let's start with something simple.

Looking for a way to fill the screen with a solid colour?

The Spacer component expands to fill the available space. Add it at the root of the layout to simply fill the space with a colour.

    var body: some View {
        Spacer().background(Color.green)
    }

If you want to layer things on top of it, you can use a ZStack. Put the Spacer as the first item in the ZStack so your ZStack expands to fill the screen.

struct WinView: View {
    @State private var animate = false

    var body: some View {
        ZStack() {
            Spacer().background(Color.green)
            Text("You win!")
                .lineLimit(1)
                .font(Font.custom("Helvetica Bold", size: 200))
                .foregroundColor(Color.white)
        }
    }
}