swift - 使.a UICollectionViewCell 的高度/宽度取决于屏幕大小
问题描述
我有三合一CollectionViews
。ViewController
如果我现在设置约束,每列的单元格数量会发生变化,这会破坏我的应用程序。有没有一种特殊的方法——没有限制——来处理这个问题?
解决方案
实施
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 ...
...
}
推荐阅读
- visual-studio-2019 - 在 Visual Studio 2019 的工具栏中添加分隔符
- javascript - 从一个 HTML 表中复制所有行并附加到另一个表
- julia - 使用 ./startup.jl 文件设置 nprocs()
- oracle - 未找到 Oracle 客户端和网络组件。源 Oracle 数据库 SO AIX
- swift - 过早调用完成处理程序
- reactjs - Chrome 开发者工具显示 JSON 对象的不同值
- r - 如何在 tmap 中指定多面板布局两侧的标签?
- twilio - 无法从 Twilio Studio 创建任务
- java - 错误:对重载定义的模糊引用,Scala 中的 ND4J
- python - Python for Maya - 滑块换色器