0

I want to show images in a collection view in a grid format in varying sizes with a plus sign (i.e. +2,+3 etc.). It'll look like so...

enter image description here

I came to know that using UICollectionViewFlowLayout this can be achieved. So I referred to this Stack Overflow question and tried adding this line of code. But it didn't work

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

        switch indexPath.item {
        case 0,1:
            return CGSize(width: (UIScreen.main.bounds.width - 16) / 2, height: (UIScreen.main.bounds.width - 16) / 2)
        default:
            return CGSize(width: (UIScreen.main.bounds.width - 32) / 3, height:  (UIScreen.main.bounds.width) / 3)
        }
    }

Also, if the number of images selected is 2 or 3, then those images should be arranged like so..

enter image description here

How can I make the images appear like that...?

user308123
  • 135
  • 1
  • 12
  • i think this link might give you an idea as how to achieve it https://octodev.net/custom-collectionviewlayout/ – vgvishesh23113 Feb 20 '19 at 05:55
  • @user308123 you should create a custom UICollectionViewLayout for your collection view. Please have a look at my similar project, it will help https://github.com/Arunjos/Ainterest – arunjos007 Feb 20 '19 at 06:55
  • ok @ arunjos007 I'll have a look at it. Thanks a lot..:) – user308123 Feb 20 '19 at 06:57

0 Answers0