在 iOS14 中,用 CollectionView 实现一个 TableView 样式的列表非常简单。
使用UICollectionLayoutListConfiguration即可创建。
func createLayout() -> UICollectionViewLayout {
let configuration = UICollectionLayoutListConfiguration(appearance: .insetGrouped)
return UICollectionViewCompositionalLayout.list(using: configuration)
}
UICollectionLayoutListConfiguration
其中insetGrouped为样式。还有plain、grouped、insetGrouped、sidebar、sidebarPlain等样式。
.plain

. sidebarPlain

. sidebar

. grouped

. insetGrouped

网友评论