Skip to content

Instantly share code, notes, and snippets.

@jeffbailey
Created March 30, 2014 11:06
Show Gist options
  • Save jeffbailey/9871153 to your computer and use it in GitHub Desktop.
Save jeffbailey/9871153 to your computer and use it in GitHub Desktop.
Find the height of a string to dynamically determine the height of a label. New in iOS 7.
+ (CGSize)labelSizeForString:(NSString *)string fontSize:(CGFloat)fontSize
{
return [string boundingRectWithSize:CGSizeMake(DETAIL_TEXT_LABEL_WIDTH, 2000.0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:fontSize]} context:nil].size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment