How to make background fill entire view?

Viewed 57

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?

2 Answers

You can set the frame of VStack:

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

try this:

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