Last active
October 19, 2020 20:56
-
-
Save neilinglis/5032083 to your computer and use it in GitHub Desktop.
I expected that, all other attributes being equal, if I have two identical strings, one with font size twice the other, then NSString's sizeWithAttributes would return height of X for the first string and X*2 for the second. It doesn't. Fonts are weird, yo.
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
NSMutableParagraphStyle * paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; | |
[paragraphStyle setAlignment:NSCenterTextAlignment]; | |
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; | |
NSFont *font1 = [NSFont fontWithName:@"HelveticaNeue-Medium" size:12]; | |
NSFont *font2 = [NSFont fontWithName:@"HelveticaNeue-Medium" size:24]; | |
NSDictionary *attributes1 = @{NSFontAttributeName : font1, NSParagraphStyleAttributeName : paragraphStyle}; | |
NSDictionary *attributes2 = @{NSFontAttributeName : font2, NSParagraphStyleAttributeName : paragraphStyle}; | |
CGSize size1 = [@"Foobar" sizeWithAttributes:attributes1]; | |
CGSize size2 = [@"Foobar" sizeWithAttributes:attributes2]; | |
(lldb) p size1 | |
(CGSize) $0 = (width=39.576, height=19) | |
(lldb) p size2 | |
(CGSize) $1 = (width=79.152, height=29) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment