0

I need to create UICollectionView cell have full height but the dynamic width to fit a UIImageView's image. The UIImageView's constraints equal to cell ( contentView ). I have read about the dynamic height in this so my question is: "Is the AutoLayout allow autolayout dynamic width ?" .

1 Answers1

0

To my knowledge UICollectionView doesn't handle width automatically. However you can easily set the width via the delegate. I refer you to this post : Dynamic cell width of UICollectionView depending on label width

It was UILabels instead of UIImageViews but the method should be similar using UIImage size property instead of sizeWithAttributes of NSString.

EDIT : After some tests it turns out UICollectionView does handle cell width automatically the same way as automatic height. So the delegate is not necessary. (see this tutorial for detailed info)

However, if the images are not available immediately (remotely fetched for instance) then you should wait until all images are downloaded and then display the collection. Otherwise you will need to invalidate the layout after each image is displayed which can lead to visual glitches.

Bioche
  • 388
  • 3
  • 10