如何在不使用节的情况下在水平集合视图中生成2行

问题描述 投票:1回答:1

uicollectionview中的水平滚动只返回一行,我需要制作2行的水平滚动集合视图,就像下面的图像一样

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

uicollectionview horizontal-scrolling swift4.2 uicollectionviewdelegateflowlayout
1个回答
2
投票

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

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

            return CGSize(width: 50.0, height: collectionViewHeight / 2) //<-- Manage height and width accordingly.
        }
© www.soinside.com 2019 - 2024. All rights reserved.