How to add shadow to Form Section?

Viewed 122

I can't seem to add a shadow to a Form Section. This is what it looks like when I try:

enter image description here

Section {
    Text("Some content")
}
.background(
    Color(.systemBackground)
        .shadow(color: Color(.label), radius: 9, x: 0, y: 2)
)

I also tried to put the shadow directly on the section, but that made a shadow around the letters not the Section container.

1 Answers

Here, it is because UIKit! we should first get rid of UITableView default

backgroundColor color, then it will work.


enter image description here

enter image description here


struct ContentView: View {
    
    init() { UITableView.appearance().backgroundColor = UIColor.clear }
    
    var body: some View {
        
        Form {
            
            Section(header: Text("Setting"), content: { Text("Some text there!") })
            
            Section { Text("Some text there!") }
            
            Section { Text("Some text here!") }
            
        }
        .padding()
        .shadow(color: Color.secondary, radius: 10, x: 5, y: 5)
        .background(Color(UIColor.systemGray4).ignoresSafeArea())
        
    }
}
Related