【问题标题】:How to remove default padding for separator for List in SwiftUI?如何在 SwiftUI 中删除列表分隔符的默认填充?
【发布时间】:2022-01-03 16:45:54
【问题描述】:

我在 SwiftUI 中创建了 List,但它有额外的分隔符(分隔符)填充,我想减少前导填充并为尾随和前导使用相同的填充。

var body: some View {
    NavigationView() {
        List(modelData) { weather in
            HStack {
                Image(systemName: weather.image)
                    .frame(width: 50, height: 10, alignment: .leading)
                Text("\(weather.temp)º")
                    .frame(width: 50, height: 10, alignment: .leading)
                VStack {
                    Text(weather.city)
                }
            }.font(.title)

        }
        .navigationBarTitle(Text("World Weather"))
    }
}

【问题讨论】:

    标签: ios swift swiftui


    【解决方案1】:

    我们可以删除默认分隔符并使用 own 与任何填充(绘图等),如下例Divider

        VStack {
            // Row content here
            Divider().padding(.horizontal)    // << separator here !!
        }
        .listRowSeparator(.hidden)
    

    【讨论】:

      猜你喜欢
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 2023-02-08
      • 1970-01-01
      • 2020-06-28
      相关资源
      最近更新 更多