首页 > 解决方案 > 如何使用 swift 4 显示这样的 collectionView?

问题描述

在此处输入图像描述collectionView您好,我想像上面的图片一样显示多张图片。我可以在 的帮助下显示两行和三列UICollectionViewDelegateFlowLayout,但无法做到这一点。非常感谢您的帮助。

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {        
        switch indexPath.item {
        case 0,1:
            return CGSize(width: (UIScreen.main.bounds.width - 4) / 2, height: (UIScreen.main.bounds.width - 4) / 2)
        default:
            return CGSize(width: (UIScreen.main.bounds.width - 6) / 3, height:  (UIScreen.main.bounds.width) / 3)
        }

    }

标签: iosuicollectionviewswift4uicollectionviewflowlayout

解决方案


推荐阅读