CollectionView sizeForItemAtIndexPath never called

前端 未结 15 1453
一整个雨季
一整个雨季 2020-12-24 11:17

This is driving me crazy! I have a UICollectionViewController as shown below:

class PhrasesCompactCollectionViewController: UICollectionViewController
         


        
15条回答
  •  太阳男子
    2020-12-24 12:04

    In Swift 3+ Use this method:

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return CGSize(width:(collectionView.frame.height-90)/2, height: 100)
    }
    

    Make sure that your class complies both Delegate

    • UICollectionViewDelegate

    • UICollectionViewDelegateFlowLayout

提交回复
热议问题