Swift, Change width of UICollectionViewCell and UILabel(inside the cell) programmatically

前端 未结 1 1637
心在旅途
心在旅途 2021-02-15 14:44

I\'ve set the width of a cell(UICollectionViewCell) to be equal to the width of the UICollectionView and I\'m trying to do exactly the same thing with the UILabel that is includ

1条回答
  •  野的像风
    2021-02-15 15:19

    It doesn't work because by the time this method is called, the collection view already knows how big the cell should be because it has got it from the flow delegate method:

    optional func collectionView(_ collectionView: UICollectionView,
                      layout collectionViewLayout: UICollectionViewLayout,
                 sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
    

    This is where you should be setting the size of your cells.

    0 讨论(0)
提交回复
热议问题