How to get the correct frame of UICollectionViewCe

2019-07-26 10:28发布

I have a UICollectionView and I set it's cellSize in viewDidLoad:

    let cellWidth = self.view.frame.width / 2
    self.collectionViewFlowLayout.itemSize = CGSize(width: cellWidth, height: 100)`

I try to add a gradient layer to my custom UICollectionViewCell. But the frame size is the one I set from storyboard. I can't get the correct, calculated frame size in my UICollectionViewCell subclass's layoutSubviews method.

How am I going to get the correct frame size?

0条回答
登录 后发表回答