Skip to content

Instantly share code, notes, and snippets.

@mamaz
Last active August 29, 2015 13:56
Show Gist options
  • Save mamaz/9066782 to your computer and use it in GitHub Desktop.
Save mamaz/9066782 to your computer and use it in GitHub Desktop.
+(CGSize)getLabelSizeWordWrapWithString:(NSString*)string font:(UIFont*)font
constrainedToSize:(CGSize)constrainedSize
{
if (IOS_VERSION_LESS_THAN_7) {
CGSize size = [string sizeWithFont:font
constrainedToSize:constrainedSize
lineBreakMode:NSLineBreakByWordWrapping];
return size;
} else {
// for iOS7
CGRect rect = [string boundingRectWithSize:constrainedSize
options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading
attributes:@{NSFontAttributeName: font}
context:nil];
return CGRectIntegral(rect).size;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment