如何在不使用ForEach的情况下从SwiftUI中的列表中删除行分隔符? [英] How to remove the line separators from a List in SwiftUI without using ForEach?

查看:107
本文介绍了如何在不使用ForEach的情况下从SwiftUI中的列表中删除行分隔符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码来显示自定义行的列表.

I have this code to display a list of custom rows.

struct ContentView : View {
    var body: some View {
        VStack(alignment: .leading) {
            List(1...10) {_ in
                CustomRow()
            }
        }
    }
}

但是,我想删除每一行上的行.我试过不使用List而是在ScrollView内使用ForEach,但是它完全删除了所有样式,包括其填充和边距.我只想删除这些行而已.

However, I want to remove the line on each row. I tried not using List and instead using ForEach inside ScrollView but it completely removes all the styling including its padding and margins. I just want to remove the lines and nothing else.

请帮助,谢谢.

推荐答案

iOS 14:

您可以考虑在ScrollView内使用LazyVStack.

iOS 13的SwiftUI List后面有一个UITableView.因此请删除

There is a UITableView behind SwiftUI's List for iOS 13. So to remove

您需要tableFooterView并删除

您需要separatorStyle成为.none

init() {
    if #available(iOS 14.0, *) { 
        // iOS 14 doesn't have extra separators below the list by default.
    } else {
        // To remove only extra separators below the list:
        UITableView.appearance().tableFooterView = UIView()
    }

    // To remove all separators including the actual ones:
    UITableView.appearance().separatorStyle = .none
}

var body: some View {
    List {
        Text("Item 1")
        Text("Item 2")
        Text("Item 3")
    }
}

请注意,默认情况下,静态列表不会在列表下方显示额外的分隔符

Note that a static list doesn't show extra separators below the list by default

这篇关于如何在不使用ForEach的情况下从SwiftUI中的列表中删除行分隔符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆