UICollectionView autosize height

前端 未结 9 1677
孤城傲影
孤城傲影 2020-12-04 07:02

How do I properly resize a UICollectionView so that it fully displays its contents? I have tried many things, including setting its frame, calling reloadData an

9条回答
  •  自闭症患者
    2020-12-04 07:36

    For me it is even simpler I think

    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    
    {
    //add following code line after adding cells, before Return
    ...........
    .........
    scrollView.contentSize = = collectionView.contentSize;
    
    //now scrollView size is equal to collectionView size. No matter how small or big it is.
    
    return cell;
    }
    

提交回复
热议问题