更改CollectionView单元格的垂直间距

时间:2015-08-28 02:21:45

标签: ios objective-c uicollectionview

使用UICollectionView并在集合视图的委托方法中更改项目的大小,如下所示

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

    lastIndex = 0;
    layoutDiff = 4;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == (lastIndex + layoutDiff) - 1){
        layoutDiff = (layoutDiff == 4)?5:4;
        lastIndex = indexPath.row + 1;
        return CGSizeMake(213.2, 213.2);
    }

    return CGSizeMake(106.6, 106.6);
}

这是我当前的屏幕。

enter image description here

并且所有下面的单元格都遵循这种行为,意味着我想要的模式就像一个集合视图项目一样大,这取决于我的逻辑,我想让它变大但我不想要这个空间。我想如果空间不在那里那么一切都会正确的。任何人都可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

FlowLayout无法为此提供帮助。

你需要实现你的UICollectionLayout的子类。

以下是一些关于自定义集合视图布局的文章。

自定义收藏视图布局。

https://www.objc.io/issues/3-views/collection-view-layouts/

知道何时对流布局进行子类化 https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/UsingtheFlowLayout/UsingtheFlowLayout.html#//apple_ref/doc/uid/TP40012334-CH3-SW4

相关问题