Skip to content

Instantly share code, notes, and snippets.

@ramakser
Last active June 27, 2016 09:08
Show Gist options
  • Save ramakser/16a2580b16cc9ba07f44a64eebbb7e41 to your computer and use it in GitHub Desktop.
Save ramakser/16a2580b16cc9ba07f44a64eebbb7e41 to your computer and use it in GitHub Desktop.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UITabBarItem *item = self.items[indexPath.row];
CGSize size = CGSizeMake(100, 30);
CGRect expectedLabelSize = [item.title boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName:[UIFont VWTextOfficeRegularWithSize:12] } context:nil];
CGFloat height = CGRectGetHeight(collectionView.frame);
CGFloat width = ceilf(expectedLabelSize.size.width) + 40;
return CGSizeMake(width, height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment