[英]UICollectionView using cells with different heights
所以我有一个集合视图控制器,它有3个单元格,因为每个单元格都有不同的布局。 我的图片显示了这个:
它们都有不同的单元格标识符,因此在我的cellForItemAtIndexPath函数中,我可以创建特定的单元格,如:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell;
if(indexPath.row == 0)
{
static NSString *identifier = @"Cell1";
cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
[cell setNeedsLayout];
}
else if(indexPath.row == 1)
{
static NSString *identifier = @"Cell2";
cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
[cell setNeedsLayout];
}
else
{
static NSString *identifier = @"Cell3";
cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
[cell setNeedsLayout];
}
return cell;
}
但是当我模拟它时,所有单元格的大小都相同:
有没有办法强制单元格达到我定义的大小,或者有更合适的方法吗?
试试这个: UICollectionView中不同单元格大小的自定义布局
或使用此方法:
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.