【发布时间】:2017-05-23 11:08:01
【问题描述】:
在我的代码中,我创建了具有页眉和页脚的 UICollectonView。
我的页脚高度应该是动态的,取决于文本大小。
文本可以从 1 行到 100 行。
这是我的代码。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width:collectionView.frame.size.width, height:50.0)
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionElementKindSectionFooter:
let footer = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionFooter, withReuseIdentifier: "SectionFooterCollectionReusableView", for: indexPath) as! SectionFooterCollectionReusableView
footer.lblDescription.text = composition?.desc
return footer
default: return UICollectionReusableView()
}
}
【问题讨论】:
-
设置
label.numberOfLines = 0,你熟悉NSLayoutConstraints/NSLayoutAnchor吗?
标签: ios swift uicollectionview