iOS 14:
默认情况下, iOS 14 不会在列表下方显示额外的分隔符,要删除所有分隔符,您需要使用 a LazyVStack
inside aScrollView
来代替。(因为 iOS不再支持 SwiftUI 列表的外观)。

iOS 13:
⚠️ 此方法已弃用,并且不适用于 iOS 14
不需要Section
或.grouped
风格!
iOS 13的UITableView
SwiftUI 背后有一个。所以要删除List
- 额外的分隔符(在列表下方):
你需要一个tableFooterView
and 来删除。
请注意, iOS 14 默认情况下不会在列表下方显示额外的分隔符。
- 所有分隔符(包括实际分隔符):
你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")
}
}
请注意,它消除了所有表格/列表的分隔符。onAppear()
因此,您可以根据需要以或等方法切换它。