【问题标题】:Swift - Header UICollectionViewController dynamic heightSwift - 标题 UICollectionViewController 动态高度
【发布时间】:2018-08-03 19:33:29
【问题描述】:

我目前正在编写我的应用程序的主页,这是一个带有标题的UICollectionViewController

在标题中,我有很多LabelsButtons。 由于设置了约束,我想要一个动态高度,但我没有找到如何做到这一点或在 stackoverflow 上没有任何答案......

标题的屏幕截图(截断)

  1. 使用 Firebase 获取数据
  2. 将数据发送到 UICollectionReusableView
  3. 标签已在其中更新

所以流程是这样的:

override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {

      let headerViewCell = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header", for: indexPath) as! WodCollectionReusableView

      headerViewCell.wod = self.wod // pass the info
      headerViewCell.layoutIfNeeded()

      return headerViewCell
}

如果您知道是否有一种方法可以做到这一点,就像我们可以为细胞做的那样,那就太棒了。

【问题讨论】:

    标签: swift swift3 uicollectionview


    【解决方案1】:
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize{
        return CGSize(width: self.myCollectionView.bounds.width, height: self.mylabel.bounds.height)
    }
    

    试试这个可能对你有帮助

    【讨论】:

    • 谢谢,但鉴于标签位于 UICollectionReusableView 中,我可以访问 self.mylabel.bounds.height
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-10
    • 2015-09-15
    • 1970-01-01
    • 2018-02-09
    相关资源
    最近更新 更多