Created
January 13, 2015 02:31
-
-
Save majie1993/06e08cb91167f0730ac6 to your computer and use it in GitHub Desktop.
Calculate the width of a String
From http://stackoverflow.com/questions/1324379/how-to-calculate-the-width-of-a-text-string-of-a-specific-font-and-font-size
This file contains hidden or 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
UIFont *font = [UIFont fontWithName:@"Helvetica" size:30]; | |
NSDictionary *userAttributes = @{NSFontAttributeName: font, | |
NSForegroundColorAttributeName: [UIColor blackColor]}; | |
NSString *text = @"hello"; | |
... | |
const CGSize textSize = [text sizeWithAttributes: userAttributes]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment