iOS UICollectionView prototype cell size property ignored

后端 未结 9 2034
花落未央
花落未央 2021-01-30 19:51

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 ret

9条回答
  •  难免孤独
    2021-01-30 20:28

    In Swift you can call sizeForItemAtIndexPath delegate method to set the size for each cell.

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
    
            if indexPath.row == 0 {
                    // Set the size for cell no. 0
             }else if indexPath.row == 1 {
                   // Set the size for cell no. 1
            }
        }
    

    I hope that helps. Thanks!

提交回复
热议问题