2016-05-22 11 views
0

だから、私はcellForItemAtIndexPathからではなくcellForItemAtIndexPathからUICollectionViewCellの高さを設定する方法は?

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 

私はそれをどのように行うことができますからUICollectionViewCellの高さを設定したいですか?だから私はないあなたはまだsizeForItemAtIndexPathを使用する必要がcollectionViewLayout: sizeForItemAtIndexPath

答えて

2

で、cellForItemAtIndexPathに私の細胞に高さと幅を与えたい、しかし、あなたはあなたの迅速なファイルの先頭にパブリック変数を宣言することがあります。

var cellSize = CGSize() 

cellForRowAtIndexPathデリゲート書き込みでreturn cell前にこのような何か:その後、

cellSize = CGSizeMake(100, 100) // set your desired width and height 

あなたがそれらを提供することができます
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 
    return cellSize 
} 
0

一つの方法は、UICollectionViewFLowLayout

UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout*) self.CollectionViewLayout.collectionViewLayout; 
    flowLayout.estimatedItemSize = CGSizeMake(self.view.frame.size.width,yourheight); 

と高さを推定したが、すべてのセルが異なる高さを持っている必要がある場合、あなたは sizeForItemAtIndexPath方法フォームUICollecionViewControllerを実装する必要があります。

>  (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout 
> sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ 
>  return CGSizeMake(width, height); 
>  
>  } 
関連する問題