UICollectionViewCell content wrong size on first load

前端 未结 5 1731
感情败类
感情败类 2020-12-15 02:52

I have a added a UICollectionView to my UIViewController and have made a custom cell for it.

I set the size of the cell using the siz

5条回答
  •  清歌不尽
    2020-12-15 03:43

    For those using Storyboard + AutoLayout, and choosing which constraints are active at runtime:

    When using dequeueReusableCell, on first load, the cell is created but its view has not been initialised, so the constraint changes aren't saved - whatever you have set in Storyboard is used. Solution for me was to update the constraints after the view has loaded:

    override func layoutSubviews() {
        super.layoutSubviews()
        adjustIconWidths()
    }
    

提交回复
热议问题