Swift 使.UICollectionViewCell的高度/宽度取决于屏幕大小
我在一个Swift 使.UICollectionViewCell的高度/宽度取决于屏幕大小,swift,xcode,uicollectionview,Swift,Xcode,Uicollectionview,我在一个ViewController中有三个collectionview。如果现在设置约束,则每列的单元格数量将发生变化,这将破坏我的应用程序。有没有一种没有限制的特殊方法来处理这个问题?实现 let scW = UIScreen.main.bounds.width let scH = UIScreen.main.bounds.height func collectionView(_ collectionView: UICollectionView, la
ViewController
中有三个collectionview
。如果现在设置约束,则每列的单元格数量将发生变化,这将破坏我的应用程序。有没有一种没有限制的特殊方法来处理这个问题?实现
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 ...
...
}
让scW=UIScreen.main.bounds.width
设scH=UIScreen.main.bounds.height
func collectionView(collectionView:UICollectionView,
布局集合视图布局:UICollectionViewLayout,
sizeForItemAt indexPath:indexPath)->CGSize{
如果collectionView==col1{
返回CGSize(宽度:,高度:)//屏幕宽度/高度的提供比率
}
其他的
...
}
之后我该怎么办?再次设置约束?这将过度写入约束,因此无论如何都不需要约束啊,太好了,我看到了。现在宽度合适了。高度实际上并没有改变,即使我在代码中增加了它