SwiftUI 2.0 how to change the background color of a form section [duplicate]
Asked Answered
R

1

5

I am trying to changing the black area of a section inside of a form using SwiftUI.

Since Swift 2.0 in iOS 14, a form shows these with a of padding, but using background and foreground for the colors, does not change the part I need to change.

Is there a modifier that changes the black part (in dark mode) to any other colour?

So far I have:

Form {
    Section(header: Text("User Details")) {
        Text("Name:").background(Color.red)
        Text("Email:").foregroundColor(Color.red)
    }
}

enter image description here

Rhetic answered 14/11, 2020 at 1:22 Comment(0)
P
12

try this:

Form {
    Section(header: Text("User Details")) {
         Text("Name:").background(Color.red)
         Text("Email:").foregroundColor(Color.red)
    }.listRowBackground(Color.green)
}
Pulido answered 14/11, 2020 at 2:5 Comment(2)
If you want to make it .clear SwiftUI will ignore you and place a dark default view as normal unless you set the following appearance proxy on view appearance: .onAppear { UITableViewCell.appearance().backgroundColor = UIColor.clear }Deferred
This one is really an unexpected and weird behaviour that bugged me for a while. Thanks! @DeferredPurim

© 2022 - 2024 — McMap. All rights reserved.