Skip to content

Instantly share code, notes, and snippets.

@joshaber
Created December 30, 2010 00:18
Show Gist options
  • Save joshaber/759259 to your computer and use it in GitHub Desktop.
Save joshaber/759259 to your computer and use it in GitHub Desktop.
- (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