Home > Back-end >  SwiftUI background color from Text ignores safe area even though it is NOT set to ignore
SwiftUI background color from Text ignores safe area even though it is NOT set to ignore

Time:01-15

My problem is the title itself. I follow this tutorial in order to understand the VStack, HStack, ZStack and spacers: enter image description here

Even though I have not specified for the background color of the Text view ,to ignore safe areas, they ignore it. Is this the true end result ? Because on the video the result is different. Thank you in advance for any replies !

CodePudding user response:

Instead of pure color (which seems fill everything now, maybe bug maybe not), use colored shape as a background, which is valid in any case:

demo

var body: some View {
    VStack{
        HStack{
            Text("Left side")
              .background(Rectangle().fill(Color.green))    // << !!
            Spacer()
        }
        Spacer()
        HStack{
            Spacer()
            Text("Right Side")
              .background(Rectangle().fill(Color.green))   // << !!
        }
    }
}

Tested with Xcode 13.2 / iOS 15.2

  •  Tags:  
  • Related