UICollectionView垂直填充问题

时间:2014-03-07 18:51:52

标签: ios uicollectionview

我已经实施了这个方法

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

因此该方法在任何情况下都会调用,因为如果我更改为UIEdgeInsetsMake(0, 0, 100, 0),我可以在每个部分的顶部看到100 pt填充。但是如果我设置零值,那么行之间仍然有大约10 enter image description here pt。

1 个答案:

答案 0 :(得分:1)

在流程布局中设置

UICollectionViewFlowLayout * flow = [[UICollectionViewFlowLayout alloc]init];
flow.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
flow.scrollDirection = UICollectionViewScrollDirectionVertical;
flow.minimumInterItemSpacing = 0; // space between cells in row
flow.minimumLineSpacing = 0; // space between rows

yourCollectionView = [[UICollectionView alloc]initWithFrame:someFrame collectionViewLayout:flow];

或代表方法:

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
    // space between cells on different lines
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
    // space beetween cells in same row
}