如何在不使用部分的情况下在水平集合视图中制作 2 行

How to make 2 rows in horizontal collection view without using sections

UICollectionView 中的水平滚动只有returns 一行,我需要制作一个水平滚动的2 行集合视图,如下图

[1]: https://i.stack.imgur.com/Vs1kt.png :[1]

您需要设置 CollectionView 的固定高度,然后在 returns CGSize 的 UICollectionViewDelegateFlowLayout 下使用 sizeForItemAt()。您必须像这样管理单元格高度。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

            return CGSize(width: 50.0, height: collectionViewHeight / 2) //<-- Manage height and width accordingly.
        }