首页 > 解决方案 > 使.a UICollectionViewCell 的高度/宽度取决于屏幕大小

问题描述

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

标签: swiftxcodeuicollectionview

解决方案


实施

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 ...
  ...
}

推荐阅读