SwiftUI Row Height of List - how to control?

前端 未结 1 1355
时光取名叫无心
时光取名叫无心 2021-02-12 06:20

I have a simple List in SwiftUI. Code and Screenshot included below. I would like to reduce the height of each row in the list (so less space between lines and text lines closer

1条回答
  •  粉色の甜心
    2021-02-12 06:42

    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:

    0 讨论(0)
提交回复
热议问题