I want to set the width of UICollectionViewCell dynamically.
I found some code in swift and I want the code in Objective-C.
let flowLayout = col
in case collection view cell has text, you just need to reference some label in the scene without width constraint for it, then every time in size for item, just assign to it your text, and call
Objective C:
NSString *text = [arrayOfItems objectAtIndex:indexPath.item];
_outletoflbl.text = text;
return CGSizeMake(_outletoflbl.intrinsicContentSize.width + 60, 40);
Swift:
let text = arrayOfItems[indexPath.item]
_outletoflbl.text = text
return CGRect(width:_outletoflbl.intrinsicContentSize.width + 60, height: 40)
The key is _outletoflbl, the label to assign it text to get width of it best fitting font and other attributes you assign from interface builder!
Check result: