Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the background color of a form?

I'm not able to change the background color of a Form in SwiftUI for iOS < 16. It always takes default form backgroundcolor depending on which color scheme is selected in the iPhone settings. All solution I found here to set the UITableView.appearance().backgroundColor = .clear also don't work. Do any of you have a solution?

I tried different solutions:

  • UITableView.appearance().backgroundColor = .clear

  • GeometryReader { geometry in
                ZStack {
                    Rectangle().foregroundColor(.white).frame(width: geometry.size.width, height: geometry.size.height)
                    Form {
                        // your form content here
                    }
                }
            }
    
  • struct FormBackgroundColorModifier: ViewModifier {
        var color: Color
    
        func body(content: Content) -> some View {
            ZStack {
                color.edgesIgnoringSafeArea(.all)
                content
            }
        }
    }
    
    struct MyForm: View {
        var body: some View {
            Form {
    
            }
            .modifier(FormBackgroundColorModifier(color: .white))
        }
    }
    
    
like image 366
floro Avatar asked Oct 29 '25 17:10

floro


1 Answers

Just use .scrollContentBackground(.hidden)

struct ContentView: View {
    
    var body: some View {
        Form {
            Text("A")
            Text("B")
            Text("C")
        }
        .scrollContentBackground(.hidden)
        .background(.red)
    }
}

enter image description here

like image 85
Ashley Mills Avatar answered Oct 31 '25 13:10

Ashley Mills