Resize UICollectionView cells after their data has been set

前端 未结 4 1358
日久生厌
日久生厌 2020-12-07 15:37

My UICollectionView cells contain UILabels with multiline text. I don\'t know the height of the cells until the text has been set on the label.

-(CGSize)c         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 16:14

    subclass UICollectionViewCell and override layoutSubviews like this

    hereby you will anchor cell leading and trailing edge to collectionView

    override func layoutSubviews() {
            super.layoutSubviews()
    
            self.frame = CGRectMake(0, self.frame.origin.y, self.superview!.frame.size.width, self.frame.size.height)
        }
    

提交回复
热议问题