我创建了一个自定义集合视图单元格。它有 UILabel , UIView , UIButton ,然后是 UITextView 。
要求是:
答案 0 :(得分:-1)
使用此方法并计算适合您的大小并将其返回。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let Labell : UILabel = UILabel()
Labell.text = self.items[indexPath.item]
let labelTextHeight = Labell.intrinsicContentSize.height
//calculate size for UIView, UIButton, TextView and then add it
return CGSize(width: /*fix width*/, height: labelTextHeigh + /*your UIView height and other height*/)
}
不要忘记从viewController
UICollectionViewDelegateFlowLayout