Created
December 30, 2010 00:18
-
-
Save joshaber/759259 to your computer and use it in GitHub Desktop.
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
- (NSSize)sizeWithSize:(NSSize)size { | |
if([self length] < 1) return NSZeroSize; | |
NSTextContainer *textContainer = [[[NSTextContainer alloc] initWithContainerSize:size] autorelease]; | |
NSTextStorage *textStorage = [[[NSTextStorage alloc] initWithAttributedString:self] autorelease]; | |
NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init] autorelease]; | |
[layoutManager addTextContainer:textContainer]; | |
[textStorage addLayoutManager:layoutManager]; | |
[layoutManager setHyphenationFactor:0.0]; | |
// NSLayoutManager is lazy so for it to layout | |
(void) [layoutManager glyphRangeForTextContainer:textContainer]; | |
return [layoutManager usedRectForTextContainer:textContainer].size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment