UICollectionView with different cell size

非 Y 不嫁゛ 提交于 2019-12-04 05:27:44

Use UICollectionViewDelegateFlowLayout method.

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {

        let width : CGFloat
        let height : CGFloat

        if indexPath.item == 0 {
            width = 100
            height = 100
        } else {
            width = 50
            height = 50
        }
        return CGSizeMake(width, height)

}

Without creating a custom layout of collection view it is not possible to achieve what you want.

You can create custom cell size using its delegate method sizeforitematindexpath.

Also, check this link which helps to create a custom layout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!