需求是这样的:一个列表 UIKit框架中就是个tableView 然后去处tableViewCell的分割线
SwiftUI中是使用List去替代TableView的实现的 去除List的分割线方法如下:
iOS 13的情况下 你写一个modifier
struct ListRemoveSeparator: ViewModifier {
func body(content: Content) -> some View {
content
.onAppear(perform: {
UITableView.appearance().tableFooterView = UIView()
UITableView.appearance().separatorStyle = .none
})
.onDisappear(perform: {
UITableView.appearance().tableFooterView = nil
UITableView.appearance().separatorStyle = .singleLine
})
}
}
然后在你实现的List后面进行调用就行了
List {
}.modifier(ListRemoveSeparator())
这样就行了 就可以去掉List的分割线了
iOS14的情况下是支持LazyVStack的 所以可以使用ScrollView搭配LazyVstack来实现
ScrollView {
LazyVStack(content: {
}
)
}
这样就行了。
LazyVStack就类似于Object-C UIKit框架里面的CollectionView