SwiftUI Row Height of List – how to control?

Use Environment variable to set min Height of the row in the list and after that change the HStack frame height to your desired height.

Here is the code:

var body: some View {
    VStack {
        Text("Pressure Readings")
            .font(.system(size: 30))
        List(pressureList) { row in
            HStack {
                Spacer()
                Text(row.timeStamp)
                Text("--->")
                Text(String(row.pressureVal))
                Spacer()
            }.frame(height: 10)
        }.environment(\.defaultMinListRowHeight, 10)
    }
}

Here is the output:

enter image description here

Leave a Comment