Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView垂直填充问题_Ios_Uicollectionview - Fatal编程技术网

Ios UICollectionView垂直填充问题

Ios UICollectionView垂直填充问题,ios,uicollectionview,Ios,Uicollectionview,我已经实施了这个方法 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{ return UIEdgeInsetsMake(0, 0, 0, 0); } 因此,该方法在任何情况下都会调用,因为如果我使用UIEdgeIns

我已经实施了这个方法

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

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

在流布局中设置该值

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
}

问题出现在故事板中,原因是UICollectionViewCell的自定义大小和UICollectionView中的单元格大小具有不同的值,但感谢您的回答