UICollectionView using sections leaves a gap between cells

前端 未结 2 1114
你的背包
你的背包 2020-12-21 05:23

I\'m using a UICollectionView to show several sections of data. These sections have a fixed number of items. I want all the items to show in a continuous grid.

Right

相关标签:
2条回答
  • 2020-12-21 05:33

    Use like this

    It will solve Gap problem

    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
    
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 2;
    
    0 讨论(0)
  • 2020-12-21 05:51

    To remove those gaps you need to create custom layout which will act as layout for your collection view. This class will child class for UICollectionViewFlowLayout.

    Then you can override below two methods and can create your own custom layout as you want.

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

    UICollectionViewLayoutAttributes is class which will deal with cell position, frame, Zindex etc

    You can also use below properties.

     collectionView:layout:minimumInteritemSpacingForSectionAtIndex:
     collectionView:layout:minimumLineSpacingForSectionAtIndex:
    
    0 讨论(0)
提交回复
热议问题