[英]Dynamic height for custom collection view cell by using autolayouts
I had created a custom collection view cell. 我创建了一个自定义集合视图单元格。 It has a UILabel , UIView , UIButton and then UITextView . 它具有UILabel , UIView , UIButton和UITextView 。
Requirements are : 要求是 :
The constraints that I applied are: 我应用的约束是:
use this method and calculate the size that is appropriate for you and return it. 使用此方法并计算出适合您的尺寸并返回。
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*/)
}
don't forget to extend your viewController
from UICollectionViewDelegateFlowLayout
不要忘记延长您viewController
从UICollectionViewDelegateFlowLayout
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.