Search code examples
iosxcodelayoutcollectionviewflowlayout

Collection View Layout Issue


I have used collection view to create the following layout:

enter image description here

I have set the size of the layout using sizeForItemAtIndexPath method of collection view and using flow layout but what I could achieve is:

enter image description here

I tried reducing the width and height but even then I cannot achieve the two elements below each other.


Solution

  • Creating a layout that behaves like you first picture is simply not possible without writing a custom subclass of UICollectionViewLayout (as rdelmar mentioned in the comment). But I have recently experienced a similar problem as you. For me this github project was very helpful: https://github.com/chiahsien/CHTCollectionViewWaterfallLayout

    It looks like you can also use this layout for you CollectionView.