Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView with different cell size

My goal is to create a UICollectionView with a layout as depicted below.

Is this possible without creating a custom UICollectionViewLayout?

like image 492
Ujesh Avatar asked May 25 '17 13:05

Ujesh


Video Answer


1 Answers

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)

}
like image 105
Dejan Atanasov Avatar answered Oct 02 '22 10:10

Dejan Atanasov