SwiftUI, shadow only for container

Viewed 6258

For example, I have this view:

import SwiftUI

struct TarifsScreen: View {  
    var body: some View {        
        GeometryReader { geometry in            
            VStack {                
                VStack {
                    Spacer()
                    Text("Text1")
                    Spacer()
                    Text("Text2")
                    Spacer()
                    Text("Text3")
                    Spacer()                    
                }
            }
            .frame(width: geometry.size.width, height: geometry.size.height)
            .shadow(color: Color.white, radius: 10, x: 0, y: 0)
        }
    }
}

How can I apply shadow only for VStack, not for all elements inside VStack? May be I can do it with ZStack and two containers?

1 Answers

Add background and apply shadow to it, like in below example

demo

  VStack {
    ...
  }
  .background(Color.white // any non-transparent background
    .shadow(color: Color.red, radius: 10, x: 0, y: 0)
  )
  .frame(width: geometry.size.width, height: geometry.size.height)
Related