删除collectionview中各节之间的空格

如何调整集合视图的各个部分之间的间距。

在此处输入图像描述

可以通过调整集合视图布局的参数来调整标题高度。 以下是相同的代码:

 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { //{top, left, bottom, right} if ([[sectionHeaderArray objectAtIndex:section] boolValue]) { return UIEdgeInsetsMake(10, 10, 10, 10); } return UIEdgeInsetsZero; } 

您可以使用该方法来实现此目的:

 - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section { //{top, left, bottom, right} if ([[sectionHeaderStatusArray objectAtIndex:section] boolValue]) { return UIEdgeInsetsMake(23, 19, 46, 14); } return UIEdgeInsetsZero; } 

这是一个布局问题,因此答案将在您用于集合视图的任何布局中。 如果您正在使用UICollectionViewFlowLayout那么您将需要设置sectionInset 。 例如

 self.collectionView.collectionViewLayout.sectionInset = UIEdgeInsetsZero;