2

I have a collection view with several labels inside located in one line. This collection view has to have horizontal scrolling and cell width calculated dynamically based on the label's sizes. I found the solution on how to make cell's width dynamic here: Dynamic cell width of UICollectionView depending on label width

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return (labels[indexPath.row] as NSString).size(attributes: nil)
}

But this method is only called when the class conforms to UICollectionViewDelegateFlowLayout which has vertical scrolling direction that doesn't suit me.

How can I make dynamic cell width for default layout with horizontal scrolling?

Elena Rubilova
  • 317
  • 3
  • 15
  • Found another solution here: https://stackoverflow.com/questions/45552444/how-to-create-horizontally-dynamic-uicollectionview-cells-swift - works better for me. – Elena Rubilova Mar 18 '18 at 01:22

0 Answers0