0

My initial task is to have equal widths of cells and make them fill the entire row of the collection view with UICollectionViewFlowLayout.

Is there a way to calculate height of cells using autolayout, but provide width from sizeForItemAtIndexPath?

Dmitry
  • 2,837
  • 1
  • 30
  • 48

1 Answers1

0

In sizeForItemAtIndexPath, calculate the height using systemLayoutSizeFittingSize: with a CGSize of your desired width, and a height large enough to fit your largest content.

e.g. for cell width of 100 (large maximum height of 999):

[collectionViewCell.contentView systemLayoutSizeFittingSize:CGSizeMake(100, 999)];

Beware though, if you have multiline UILabel's, as you will need to fiddle with preferredMaxLayoutWidth. More details, albeit for a table view, here.

Community
  • 1
  • 1
Dave Barker
  • 155
  • 1
  • 7