如何删除“行"SwiftUI 列表中的分隔符/分隔符? [英] How to remove "row" separators/dividers from a List in SwiftUI?

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

问题描述

我正在尝试删除行"来自 SwiftUI 中 List 的分隔符(在 SwiftUI 中称为分隔符).

I'm trying to remove the "row" separators (known as dividers in SwiftUI) from a List in SwiftUI.

我浏览了 List 文档,但我没有找到相应的修饰符.

I went through the List documentation, but I haven't been able to find a modifier for that.

任何帮助将不胜感激.

推荐答案

iOS 15:

今年 Apple 推出了一个新的修饰符 .listRowSeparator,可用于设置分隔符的样式.你可以通过 .hidden 来隐藏它:

iOS 15:

This year Apple introduced a new modifier .listRowSeparator that can be used to style the separators. you can pass .hidden to hide it:

List {
    ForEach(items, id:.self) { 
        Text("Row ($0)")
            .listRowSeparator(.hidden)
    }
}


iOS 14

Apple 在 iOS 14 中引入了 LazyVStack.您可以考虑使用它代替列表:


iOS 14

Apple introduced LazyVStack In iOS 14. you may consider using it instead of list for this:

ScrollView {
    LazyVStack {
        ForEach((1...100), id: .self) {
           Text("Placeholder ($0)")
        }
    }
}

请记住,LazyVStack 是惰性的,不会一直渲染所有行.因此它们的性能非常好,并且是 Apple 自己在 WWDC 2020 中推荐的.

Keep in mind that LazyVStack is lazy and doesn't render all rows all the time. So they are very performant and suggested by Apple itself in WWDC 2020.

在适用于 iOS 的 SwiftUI 的 List 后面有一个 UITableView.所以要删除

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

你需要一个 tableFooterView 并删除

你需要 separatorStyle.none

init() {
    // 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")
    }
}

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

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