Wednesday, June 26, 2024
HomeiOS Developmentios - Tips on how to drive break traces of a UILabel...

ios – Tips on how to drive break traces of a UILabel cell in a UICollectionView (Compositional Format)


I’ve a UICollectionView that acts as an inventory of tags.

It makes use of a horizontal compositional format.

Here’s a screenshot: list of tags

My drawback is that if I’ve a tag longer than the gathering’s width, it crashes with the next error:

Error: NSCollectionLayoutItem created with invalid mixture of spacing and dimension specified. This group can’t match even a single merchandise.

I perceive the error, it is smart. However how do I drive the UILabel (solely part of the UICollectionViewCell) to interrupt traces?

I’ve set numberOfLines to 0. The ViewCell is loaded from a xib with autolayout which could be very fundamental (the UILabel is sticking to superview).

And at last the code for the Compositional is the next:

let layoutSize = NSCollectionLayoutSize(widthDimension: .estimated(50), heightDimension: .estimated(20))
let merchandise = NSCollectionLayoutItem(layoutSize: layoutSize)

let group = .horizontal(layoutSize: .init(widthDimension: .fractionalWidth(1), heightDimension: layoutSize.heightDimension), subitems: [item])
group.interItemSpacing = .fastened(10)

let part = NSCollectionLayoutSection(group: group)
part.contentInsets = .init(high: 4, main: 16, backside: 4, trailing: 16)
let format = UICollectionViewCompositionalLayout(part: part)

let collectionView = UICollectionView(body: .zero, collectionViewLayout: format)

I can not work out what blocks the UILabel from breaking into a number of traces?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments