Last active
August 29, 2015 14:06
-
-
Save mamaz/74f2a31563804d744552 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get UILabel's size for wordwrapping style | |
*/ | |
+(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