Is it possible to reduce the height of a row in a SwiftUI List? I can't seem to get it to go smaller than the default height.
I tried adding .listRowInsets(EdgeInsets())
on ForEach
but it just changes the trailing and leading padding.
In UIKit, I could just use the tableView(_:heightForRowAt:)
to adjust the height to the desired size.
struct ContentView: View {
var body: some View {
List {
ForEach(1...10, id: \.self) { i in
Text("\(i)")
}
}
}
}
CodePudding user response:
Change environment property defaultMinListRowHeight like this:
List {
ForEach(1...10, id: \.self) { i in
Text("\(i)")
}.frame(height: 2)
}.environment(\.defaultMinListRowHeight, 1)