Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView, UICollectionViewFlowLayout: different cells width and same defined spacing between cells

I have overloaded the UICollectionViewFlowLayout to have a single horizontal row slider containing UIImages in each UICollectionViewCell.

In the overloaded UICollectionViewFlowLayout, I have set the minimumLineSpacing to 0 to get no spacing between UICollectionViewCells. (default is 10px)

  • In case each cell has the same width, the 0px spacing is correctly displayed

  • In case a cell has a bigger width, the 0px are no more taken into account and the default 10px between cells is applied..

I have tried to implement the following method but same result...

- (CGFloat)collectionView:(UICollectionView *)collectionView 
           layout:(UICollectionViewLayout*)collectionViewLayout 
           minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0.0;
}
  • Is it a bug ?
  • What is the "trick" to get my 0px spacing between my UICollectionViewCells with different width ?
like image 436
fvisticot Avatar asked Dec 05 '25 04:12

fvisticot


1 Answers

  1. Is it a bug? No
    This is not a bug, it is the default behavior of the UICollectionViewFlowLayout. Flow layout is a line breaking layout that means assume that it will place all your cells along a straight line and going to arrange it on the screen. Once it fill a row(no space for a new item), it will break the line and go for the next. UICollectionViewFlowLayout assures minimumLineSpacing no the exact. If your item sizes are different flow layout arranges the cells in such a way that to keep the minimum line spacing. So line size may increase but never be a lower value than you set previously.

    enter image description here

  2. I dont think it is possible with flow layout, you should use one custom layout. Check this iam not sure that you can set the spacing to zero give a try
    JSPrintDemo

like image 137
Anil Varghese Avatar answered Dec 08 '25 19:12

Anil Varghese



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!