Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertically aligned Collection view cells with varying heights

I am building a collection view, every cell has a fixed width but a varying height. There should be a border of 1 px within each cell. I have tried to find a way to make them vertically align but end up with white space in between them. Also some times the cells end up on top of each other.

Collection view example

What would be the best wat to solve this problem. I have considered subclassing UICollectionViewFlowLayout

I am currently setting the size like this:

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

    return CGSize(width: CGFloat(defaultCellSize), height: CGFloat(defaultCellSize * ratio))

}
like image 699
KMV Avatar asked Nov 09 '22 08:11

KMV


1 Answers

Try using this library https://github.com/chiahsien/CHTCollectionViewWaterfallLayout It has handled what is required.

like image 71
Ashish P. Avatar answered Nov 15 '22 06:11

Ashish P.