How to adjust the spacing between sections of collection view.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Header height can be adjusted by adjusting the params of the collection view layout. Following is the code which works perfectly fine.
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if ([[sectionHeaderArray objectAtIndex:section] boolValue]) {
return UIEdgeInsetsMake(10, 10, 10, 10);
}
return UIEdgeInsetsZero;
}
回答2:
You can use the method to implement this:
- (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;
}
回答3:
This is a layout issue, thus the answer will be in whatever layout you're using for the collection view. If you're using UICollectionViewFlowLayout
then you'll want to set the sectionInset
. e.g.
self.collectionView.collectionViewLayout.sectionInset = UIEdgeInsetsZero;
回答4:
Try this:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
if ([[sectionHeaderArray objectAtIndex:section] boolValue]) {
return UIEdgeInsetsMake(top, left, bottom, right);
}
return UIEdgeInsetsZero;
}