gpt4 book ai didi

ios - 最后 UICollectionViewCell 对齐

转载 作者:可可西里 更新时间:2023-11-01 04:34:55 25 4
gpt4 key购买 nike

我在对齐 UICollectionViewCells 时遇到问题。我有 6 个完全对齐的单元格。但是,当我更改任何一个的大小时,最后一个单元格会失去其水平对齐方式,我不知道为什么。这是我更改任何单元格高度时的结果:

enter image description here

如您所见,在此示例中,我更改了第 3 个单元格的高度,最后一个单元格不再水平对齐。这是我的代码:

- (void)viewDidLoad
{
...
FlowLayout *flowLayout = [[FlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake(152, 260);
flowLayout.sectionInset = UIEdgeInsetsMake( 5, 5, 5, 5);
flowLayout.minimumInteritemSpacing = 2.0f;
flowLayout.minimumLineSpacing = 8.0f;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
self.collectionView.collectionViewLayout = flowLayout;
...
}

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

if (indexPath.row == 2){
return CGSizeMake(152, 200);
}
return CGSizeMake(152, 270);

}

最佳答案

尝试使用 minimumInteritemSpacingForSectionAtIndex 方法来设置项目空间,而不是在 viewDidLoad 中进行设置。

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout    minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {

return 5.0;
}

关于ios - 最后 UICollectionViewCell 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23401556/

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