Ok, I did it as follows:
with element size 288x180 for my case
1/. Set item size
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { return CGSizeMake(288, 180); }
2 /. Install insetForSectionAtIndex
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(nonnull UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
3 /. Set minimumInteritemSpacingForSectionAtIndex to provide distance
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section { return 5; }
4/. When creating the cell identifier, the following was performed:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell* cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath]; if (!cell) { cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath]; cell.contentView.width = 288; cell.contentView.backgroundColor = [UIColor whiteColor]; } return cell; }
5/. For the paging effect to work correctly, make sure that collectionView.paging = NO and the UICollectionViewFlowLayout subclass use targetContentOffsetForProposedContentOffset to set the scrollview offset correctly
Not sure if this is the best way, but it gave me the desired result.
source share