如何清除“行"SwiftUI中的列表中的分隔符/分隔符? [英] How to remove "row" separators/dividers from a List in 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 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屋!