SwiftX
SwiftX

Reputation: 98

How to make background fill entire view?

I have a background with custom color bg.

I assigned it to a VStack;

VStack {
    Text("Hello :) ")
}
.background(Color("bg"))

But the color only fills whatever the VStack is displaying, how do I make it fill up the entire screen?

Upvotes: 0

Views: 139

Answers (2)

try this:

ZStack {
    Color("bg").ignoresSafeArea()
    VStack {
        Text("Hello :) ")
    }
}

Upvotes: 0

Raptor
Raptor

Reputation: 54268

You can set the frame of VStack:

VStack {
    Text("Hello :) ")
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color("bg"))

Upvotes: 1

Related Questions