UICollectionView using sections leaves a space between cells

I am using UICollectionView to display multiple sections of data. These sections have a fixed number of elements. I want all objects displayed in a continuous grid.

Now I am doing this in horizontal orientation: enter image description here

But vertically this leaves a big gap: enter image description here

I want to solve this gap between sections, because it is ugly, and it does not belong there. I would be happy to use a custom FlowLayout, but I cannot find a tutorial that points me in the right direction (I found several, but none of them specifically address this problem.)

Can someone help me solve this problem or at least point me in the right direction?

PS: I implemented partitions because I load data on the fly. Using 1 partition at the moment is not an option for me.

UPDATE Upon request, I add the values ​​used for the current FlowLayout stream. I use the standard horizontal flow layout on a full-screen (minus UINavigationBar) UICollectionView with 21 elements per section.

  • Scrolling Direction: Horizontal
  • Cell Size: 248, 196
  • Header Size: No
  • Minimum cell spacing: 10
  • Minimum line spacing: 10
  • Partition Inserts: 20, 20, 10, 10
+4
source share
2 answers

Use as

This will solve the Gap problem.

UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init]; layout.minimumInteritemSpacing = 0; layout.minimumLineSpacing = 2; 
+8
source

To remove these spaces, you need to create your own layout that will act as a layout for your collection view. This class will be a child class for UICollectionViewFlowLayout.

You can then override the two methods below and you can create your own layout as you want.

  - (NSArray*)layoutAttributesForElementsInRect:(CGRect)rect - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path 

UICollectionViewLayoutAttributes is a class that will handle cell position, frame, Zindex, etc.

You can also use the properties below.

  collectionView:layout:minimumInteritemSpacingForSectionAtIndex: collectionView:layout:minimumLineSpacingForSectionAtIndex: 
+1
source

All Articles