I have this function which is used to set size from String length. Something like that - Swift iOS - Tag collection view.
First item in categoriesItems is "Age"
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
var cellWidth : CGSize = CGSizeFromString(self.categoriesItems[indexPath.row].name);
return cellWidth
}