gpt4 book ai didi

ios - UICollectionView-使特定单元格变宽?

转载 作者:行者123 更新时间:2023-11-29 12:39:34 25 4
gpt4 key购买 nike

使用 Collection View 垂直滚动,我们有 2 列,每行有 2 个单元格。我们想制作一个特定的单元格来占据整行的位置,这样这一行就会有一个单元格,在屏幕的宽度内。

问题是,当你这样做时,它起作用了,但是你必须将所有其他单元格推到下一个位置,所以单元格 4 需要全宽:

0 1
2 3
4--
5 6

如何以更方便的方式插入所有单元格向前/实现该效果?

 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.item ==4)
cell.frame=CGRectMake(cell.frame.origin.x, cell.frame.origin.y, [UIScreen mainScreen].bounds.size.width, cell.frame.size.height);

我可以更改数据源,但它似乎不对,特别是如果你多次这样做。

最佳答案

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

if(indexPath.row==4)
return CGSizeMake([UIScreen mainScreen].bounds.size.width, 0.36*[UIScreen mainScreen].bounds.size.height);
else
return CGSizeMake(0.4*[UIScreen mainScreen].bounds.size.width, 0.36*[UIScreen mainScreen].bounds.size.height);

}

关于ios - UICollectionView-使特定单元格变宽?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25357963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com