Dynamic size UICollectionView cell Dynamic size UICollectionView cell ios ios

Dynamic size UICollectionView cell


Sorry this is super late... But maybe this will help people who haven't found an answer yet.If you have your images in an array, you can simply reference the image size and make the adjustments to the cell size from there:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{    UIImage *image = [imageArray objectAtIndex:indexPath.row];//You may want to create a divider to scale the size by the way..    return CGSizeMake(image.size.width, image.size.height); }

Hope this helps..


Maybe this layout will fit your needs. Please take a look at this project:https://github.com/betzerra/MosaicLayout

I'm not sure 100% it will totally satisfy your requirements, but in the worst case it may help you in writing your custom UICollecionViewFlowLayout (which is the only way to achieve your goal)


You can't achieve a result like the one in your question with the standard UICollectionViewFlowLayout, that in its base implementation (without subclassing) creates a grid layout.

To obtain what you want, you should create your own UICollectionViewLayout (or maybe UICollectionViewFlowLayout) subclass, where you perform all the computations needed for placing every item in the right frame.

Take a look here for a great tutorial and here for something similar to what you want.