0

私はInstagramとしてアプリケーションを作成しています。だから、私はUICollectionViewを持っています。そこで、画像、ユーザーの詳細などを投稿しました。&コメント。画像、50 - - の上にユーザ詳細420(320:320、高さ:UICollectionViewCellの高さを変更するには?

そこで、問題は、私は、細胞が

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

の寸法及び(幅と初期サイズを設定して設定すること、です画像と50 - 好きな画像の下の&のコメント))。

しかし、好き嫌いの数にもよるが、私のボトムビューのサイズは、例えば50から200に変わるかもしれない。しかし、この場合、私のUICollectionViewCellはサイズを変更しない。

私はコメントの高さに依存してそれを作ることができますどのように私はUICollectionViewCellの高さも変わるでしょうか?

私は1週間以上かけて作業しており、実装方法はわかりません。誰でも助けてくれますか?

+0

はこれを試してみてください - https://github.com/yapstudios/UICollectionViewWaterfallLayout –

+0

はあなたが正しく垂直制約を設定しましたか? – zcui93

+0

あなたはその内容に基づいてセルのサイズを計算する方法を実装し、このメソッドをsizeForItemAtIndexPathメソッドで使用する必要があります – MudOnTire

答えて

0
you need to get the height of string and then set cell size aacording to that string!!! 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
height=_collectionView.contentSize.height; 
    width = _collectionView.frame.size.width; 
    _collectionView.frame = CGRectMake(0,20,width, height); 
} 

#pragma MARK COLECTIONVIEW DELEGATE FLOW LAYOUT 
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CGSize Size =[[self.Array_LIKEs objectAtIndex:indexPath.row] sizeWithAttributes:NULL]; 
    CGFloat calculate_width =Size.width+Size.width/2+20; 
    CGFloat calculate_height=Size.height+10; 
    return CGSizeMake(calculate_width, calculate_height); 

} 
関連する問題