How to make UICollectionView with table like layout?

Generated on 9/6/2024

1 search

To create a UICollectionView with a table-like layout, you can use the new list environment trait in UIKit. This trait allows you to style cells appropriately based on the list's style, such as regular cells, headers, or footers. You can utilize UIListContentConfiguration and UIBackgroundConfiguration to adjust properties according to the list environment, which simplifies the process of configuring cells without needing to know the list style in advance.

For example, in the Files app, a UICollectionView with a compositional layout is used to display a list of locations, favorites, and tags in different styles depending on the context. In portrait mode, it uses an inset grouped appearance, while in landscape mode, it uses a sidebar appearance. This is achieved by generating content and background configurations based on the list appearance.

For more details, you can refer to the session What’s new in UIKit (07:54) where list improvements are discussed.