UICollectionView header dynamic height using Auto Layout

后端 未结 5 1075
臣服心动
臣服心动 2020-11-30 02:45

I have a UICollectionView with a header of type UICollectionReusableView.

In it, I have a label whose length varies by user input.

5条回答
  •  独厮守ぢ
    2020-11-30 03:10

    Swift 3

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize{
        return CGSize(width: self.myCollectionView.bounds.width, height: self.mylabel.bounds.height)
    }
    

    https://developer.apple.com/reference/uikit/uicollectionviewdelegateflowlayout/1617702-collectionview

提交回复
热议问题