2015-10-21 107 views
0

enter image description hereUICollectionView不同的细胞宽度

您好,我想作这样的设计,我有了不同的部分,第一个必须是不同的CollectionView ......我该怎么办?

我已经制作了不同类型的单元格,但它总是具有与故事板中指定的宽度相同的宽度...是否有任何方法可以设置单元格的宽度?

非常感谢。

回答

1

您将需要采用UICollectionViewDelegateFlowLayout协议并实施collectionView(_:layout:sizeForItemAtIndexPath:)方法。实现此方法是为了将默认情况下在集合视图中执行布局的单个项目的大小指定给UICollectionViewFlowLayout对象。

这里是链接到the relevant documentation

1

你必须使用UICollectionViewDelegateFlowLayout,特别是这种方法:

- (CGSize)collectionView:(UICollectionView *)collectionView 
        layout:(UICollectionViewLayout *)collectionViewLayout 
    sizeForItemAtIndexPath:(NSIndexPath *)indexPath 

在您需要的部分或indexPath就回到那里,你想要的大小。