我有一个部分标题和一个 UITextView 在那里,作为 Superview 的所有边的约束为 0。我也有一个流布局。在使用 viewForSupplementaryElementOfKind 填充标题可重用 View 后,我想调整标题大小。
如何在 0 节标题中访问我的 UITextView()。然后计算我的 textView 高度以返回此函数中的精确值。
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
return CGSize(width: UIScreen.main.bounds.width, height: 200.0)
}
如果有人解释一下这个案例,那就太好了。
最佳答案
我遇到了类似的问题,最终找到了这个问题:
制作 UICollectionViewDelegateFlowLayout然后执行 collectionView(_:layout:referenceSizeForHeaderInSection:)
例如:
class ViewController: UIViewController,UICollectionViewDelegateFlowLayout {
...
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
if section == 0 {
return CGSize.zero
}else{
//...
}
return CGSize(width: collectionView.frame.width, height: 60)
}
关于ios - 如何使用 referenceSizeForHeaderInSection 调整 collectionView header 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40979564/