UICollectionView Layout Issue

前端 未结 15 1762
天涯浪人
天涯浪人 2020-12-24 00:17

I am using UICollectionView using the flow layout. I have made a custom UICollectionViewCell for the same. But on running the project the console k

15条回答
  •  孤独总比滥情好
    2020-12-24 00:56

    Had this issue myself a few times when trying to create collection views with fullscreen cells. My problem was caused by laying out for 4" screen in IB/Storyboard and specifying 320*568 for item size, but running in the simulator using 3.5" screen, which has a height of 480. The solution is to specify your item size in code with something like:

    UICollectionViewFlowLayout *layout = (id) self.collectionView.collectionViewLayout;
    layout.itemSize = self.collectionView.frame.size;
    

    This ensures that the cell size is set correctly at runtime.

提交回复
热议问题