gpt4 book ai didi

swift - 使 UICollectionViewCell 的高度/宽度依赖于屏幕尺寸

转载 作者:行者123 更新时间:2023-11-28 14:02:09 24 4
gpt4 key购买 nike

我在一个 ViewController 中有三个 CollectionViews。如果我现在设置约束,每列的单元格数量会发生变化,这会破坏我的应用程序。有没有一种特殊的方式 - 没有限制 - 来处理这个问题?

最佳答案

实现

let scW = UIScreen.main.bounds.width
let scH = UIScreen.main.bounds.height

func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {

if collectionView == col1 {
return CGSize(width:<##>,height:<##>) // supply ratio of screen width/height
}
else ...
...
}

关于swift - 使 UICollectionViewCell 的高度/宽度依赖于屏幕尺寸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53462061/

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