Resize UICollectionView cells after image inside has been downloaded

前端 未结 3 1213
你的背包
你的背包 2020-12-24 00:59

I\'m building a UICollectionView and my custom cells will contain two labels and one image.

Each image is downloaded asynchronously so I don\'t know it\

3条回答
  •  北海茫月
    2020-12-24 01:29

    To resize collection view cells, you could reload the collection view and return the size of you collection view cells dynamically in the method:

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
        return [cell size];
    }
    

    In cases when the cell's size is dynamic, get the cell from the index path and return its size based on the size of the image. I usually create a method for the cell to return a dynamic size, like in the example above. You can use UIImage's size property to help return the size based on the image.

提交回复
热议问题