SwiftUI Row Height of List - how to control?

前端 未结 1 1300
野趣味
野趣味 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:44

    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)
提交回复
热议问题