I have a UICollectionView that acts as a list of tags.
It uses a horizontal compositional layout.
My problem is that if I have a tag longer than the collection's width, it crashes with the following error:
Error: NSCollectionLayoutItem created with invalid combination of spacing and size specified. This group cannot fit even a single item.
I understand the error, it makes sense. But how do I force the UILabel (only component of the UICollectionViewCell) to break lines?
I have set numberOfLines to 0. The ViewCell is loaded from a xib with autolayout which is very basic (the UILabel is sticking to superview).
And finally the code for the Compositional is the following:
let layoutSize = NSCollectionLayoutSize(widthDimension: .estimated(50), heightDimension: .estimated(20))
let item = NSCollectionLayoutItem(layoutSize: layoutSize)
let group = .horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: layoutSize.heightDimension), subitems: [item])
group.interItemSpacing = .fixed(10)
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = .init(top: 4, leading: 16, bottom: 4, trailing: 16)
let layout = UICollectionViewCompositionalLayout(section: section)
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
I can't figure out what blocks the UILabel from breaking into multiple lines?