iOS UICollectionView prototype cell size property

2019-03-08 17:12发布

I'm using a UICollectionView with two prototype cells. The prototype cells have different widths and contain different controls (image view and web view). I'm definitely returning the correct prototype cell for a given index (all the cells display the correct content), but the prototype cell size is ignored and the collection view's item size is used instead. It's not like I'm manually setting the size. What's the point of allowing the prototype cell to be sized in storyboard if the property is just ignored when it's actually displayed?

7条回答
霸刀☆藐视天下
2楼-- · 2019-03-08 18:07

If all the cells are the same size and you can set the itemSize on the UICollectionViewFlowLayout

Example:

((UICollectionViewFlowLayout *) self.collectionViewLayout).itemSize = CGSizeMake(100, 100);
查看更多
登录 后发表回答