首页 > 解决方案 > 在内容大小之前设置 UICollectionViewCell 大小

问题描述

我有一个UICollectionView动态单元格大小,在我对单元格内的内容设置比例宽度约束之前,它工作得很好。

现在看来,它UICollectionViewCell的大小与内容的大小相匹配,而实际上我想要相反 - 内容的大小需要与单元格大小成比例。我想我错过了什么......

在此处输入图像描述在此处输入图像描述

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

    let width = self.collectionView.frame.width
    let height = self.view.frame.height/2.5

    return CGSize(width: width, height: height)
}

标签: swiftuicollectionview

解决方案


有关信息,通过在 IB 中设置估计大小 = none 来修复


推荐阅读