UICollectionView dynamic line spacing

Hi guys!

I made a custom UICollectionViewFlowLayout for a carousel. In this carousel I have a featured item that is bigger than other items and any item can be featured based on his position inside visible area. Featured item or soon to be featured item size will be updated using UICollectionViewLayoutAttributes size property.

The problem is:

  • when updating size on UICollectionViewLayoutAttributes for each item, layout inter line spacing between 2 items don’t update based on their size set on attributes. I actually need to have always the same spacing between items.
    Right now I have a smaller spacing between.

You can see the bellow illustration (sc = small cell, bc = big cell and spacing) and you can observe that we have a bigger spacing between 2 small cells.
So lets say if we set layout inter line spacing to 10, sc → bc or bc → sc spacing will be like 15, and sc — sc spacing will be like 20, because of both side cells smaller size.

sc – bc – sc — sc —

A solution can be to move items horizontally or vertically based on their status, but I wonder if there is a better solution to achieve this.

Any other ideas?

Thank you! Have a nice day!

This topic was automatically closed after 166 days. New replies are no longer allowed.