if there is text in the collection view cell, you just need to refer to some label in the scene with no width limit, and then each time in size for the element just assign it your own text and call
Goal 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 a _outletoflbllabel for assigning text to it to get the width of the most suitable font and other attributes that you assign from the interface constructor!
Result of checking:

Ispha source
share