Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI, shadow only for container

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?

like image 424
alexbayker Avatar asked Mar 18 '20 12:03

alexbayker


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)
like image 65
Asperi Avatar answered Sep 20 '22 06:09

Asperi