如何在不使用ForEach的情况下从SwiftUI中的列表中删除行分隔符? [英] How to remove the line separators from a List in SwiftUI without using ForEach?
问题描述
我有这段代码来显示自定义行的列表.
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屋!