I use feature of autosizing flow layout of collectionView
self.flow = [[UICollectionViewFlowLayout alloc] init];
self.flow.scrollDirection = UICollectionViewScrollDirectionVertical;
self.flow.sectionInset = UIEdgeInsetsZero;
self.flow.estimatedItemSize = CGSizeMake(320, 48);
I want to cells will fill by width full width of CollectionView (widthCell=widthCollectionView)
But i got what autosizing work for whole size. I try playing with Content Compression/Hugging Priority - not effect.
With width of CollectionView equals 320px, i got cell size for label content size.
Constraints Horizontal : H:|-8-[img(48)]-8-[label]-8-|
How to make autosize work only for Vertical but not for Horizontal?
I found a solution.
CollectionViewCell has a delegate preferredLayoutAttributesFittingAttributes
So, this function gives you layoutAttributes sets as estimatedItemSize
You need do next (for Height)
Same you can do to prefer size, width so make constant height (frame.size.height = layoutAttributes.size.height).
If you just copy layoutAttributes and change width, will no effect!
You must call super.
Actually you are right here is the problem with the constraints priority.
To resolve the priority constraint issue you should update the
imageView Leading priority
999
and alsolabel Trailing
priority999
either programmatically or directly from InterFace Builder.Update priority programmatically by using the
KVConstraintExtensionsMaster
that I have implemented to update any constraint withoutIBOutlet reference
of Autolayout constraint.After this Now you need to calculate the only height of the cell
Dmitry Nelepov's solution in swift.
Swift 4