Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - Can't fill screen on the bottom of sheet

Tags:

swiftui

The bottom of my sheet is not filling up with color for some reason. Tried the below code, but can only fill the top safe space. Any clue?

Sheet not filling up with color

var body: some View {
    GeometryReader { geometry in
        VStack {
            Text("Hi")
                .font(.title)
        }
        .frame(width: geometry.size.width, height: geometry.size.height)
        .background(LinearGradient(gradient: Gradient(colors: [Color(hex: 0x71A2B6), Color(hex: 0xF09D51)]), startPoint: .top, endPoint: .bottom))
        .edgesIgnoringSafeArea(.all)
    }
}
like image 271
glothais-kwl Avatar asked Oct 20 '25 10:10

glothais-kwl


1 Answers

You have set .frame(width: geometry.size.width, height: geometry.size.height) which will not cover the bottom area.

And if your goal is just to have your View fill the whole screen you may not need a GeometryReader.

You can try using a ZStack instead:

struct ContentView: View {
    var body: some View {
        ZStack {
            LinearGradient(gradient: Gradient(colors: [Color(hex: 0x71A2B6), Color(hex: 0xF09D51)]), startPoint: .top, endPoint: .bottom)
            VStack {
                Text("Hi")
                    .font(.title)
            }
        }
        .edgesIgnoringSafeArea(.all)
    }
}
like image 118
pawello2222 Avatar answered Oct 22 '25 03:10

pawello2222



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!