With a simple List
in SwiftUI, how do I change/remove the standard background color for the section header
struct ContentView : View {
var body:
In beta 4, relativeWidth was deprecated. Code updated to reflect that.
Unfortunately, there's no quick parameter to set the background color. However, you can still do it:
import SwiftUI
struct ContentView : View {
var body: some View {
List {
ForEach(0...3) { section in
Section(header:
CustomHeader(
name: "Section Name",
color: Color.yellow
)
) {
ForEach(0...3) { row in
Text("Row")
}
}
}
}
}
}
struct CustomHeader: View {
let name: String
let color: Color
var body: some View {
VStack {
Spacer()
HStack {
Text(name)
Spacer()
}
Spacer()
}
.padding(0).background(FillAll(color: color))
}
}
struct FillAll: View {
let color: Color
var body: some View {
GeometryReader { proxy in
self.color.frame(width: proxy.size.width * 1.3).fixedSize()
}
}
}