Reputation: 20138
I have a List:
List {
ForEach(model.sections) { s in
Section(header: SectionView()) {
ForEach(items, id: \.self) { item in
Text(item.name)
.border(Color.mint)
}
}
}
}
.listStyle(.plain)
I have the view SectionView
I want to build for the section header:
struct SectionView: View {
var body: some View {
GeometryReader { geo in
HStack {
Text("Section Header View")
.frame(width: geo.size.width, height: 60)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.border(Color.green)
}
}
}
Unfortunately the SectionView
in the header now bleeds over the cells. The actual section header height did not change. How can I set a custom section header height?
Upvotes: 2
Views: 5165
Reputation: 257493
You should not use GeometryReader
in this case, just use height to container of section, like
struct SectionView: View {
var body: some View {
HStack {
Text("Section Header View")
}
.frame(maxWidth: .infinity, minHeight: 60) // << here !!
.border(Color.green)
}
}
gives
Tested with Xcode 13 / iOS 15
Upvotes: 1