gpt4 book ai didi

ios - 当我重新调整尺寸时更改设计 Collection View 单元格

转载 作者:行者123 更新时间:2023-11-30 12:08:36 25 4
gpt4 key购买 nike

我有一个问题,我有一个动态 Collection View ,开始时我有 3 行,但是当更改 slider 时,更改集合中的行数并调整设计,问题是设计是错误的我可以尝试使用 self.myCarouselView.collectionViewLayout.invalidateLayout()
但没有用,有什么帮助吗?在尺寸单元格中我有以下代码:

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: myCollection.bounds.size.width/CGFloat(numberOfYears), height: 120)
}

我的第一张图片: enter image description here

最后当我更改行时图像: enter image description here

好奇的是,当我点击圆圈时,设计更改为格式正确......

最佳答案

Create one class from UICollectionViewFlowLayout, override the flow layout using this code

- (instancetype)init
{
self = [super init];
if (self)
{
self.minimumLineSpacing = 1.0;
self.minimumInteritemSpacing = 1.0;
self.scrollDirection = UICollectionViewScrollDirectionVertical;
}
return self;
}

- (CGSize)itemSize
{
NSInteger numberOfColumns = 3;

CGFloat itemWidth = (CGRectGetWidth(self.collectionView.frame) - (numberOfColumns - 1)) / numberOfColumns;
return CGSizeMake(itemWidth, itemWidth);
}

关于ios - 当我重新调整尺寸时更改设计 Collection View 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46366676/

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