iOS 15:
今年,苹果公司推出了一种新的修改器.listRowSeparator
,可以用来设计分离器.您可以通过.hidden
将其隐藏:
List {
ForEach(items, id:\.self) {
Text("Row \($0)")
.listRowSeparator(.hidden)
}
}
iOS 14:
您可以考虑在ScrollView
中使用LazyVStack
(因为iOS是NOT,不再支持SwiftUI列表的外观).
iOS 13:
⚠️ 此方法已被弃用,在iOS 14上无法使用
在适用于iOS 13的SwiftUI List
后面有一个UITableView
.因此要删除
额外分离器(列表下方):
你需要一张tableFooterView
美元的钞票
所有分隔符(包括实际分隔符):
你需要separatorStyle
才能成为.none
Example of usage
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")
}
}
请注意,默认情况下,静电列表不会显示额外的分隔符