Created
August 28, 2017 08:08
-
-
Save ialex32x/343f0d84828b067effa2588e519cbda7 to your computer and use it in GitHub Desktop.
get size of string with font in cocoa touch
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
NSString *str = ...; | |
UIFont *font = [UIFont systemFontOfSize:12.0f]; | |
NSDictionary<NSString *, id> *textAttributes = @{NSFontAttributeName: font}; | |
CGRect rect = [str boundingRectWithSize:CGSizeMake(self.bounds.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:textAttributes context:nil]; | |
return rect.size.height; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment