【发布时间】:2010-12-26 22:38:57
【问题描述】:
我正在尝试在 NSView 子类上绘制文本。我正在使用 NSTextStorage、NSLayoutManager 和 NSTextContainer。我遵循 Apple 的文档,这是我用来计算每个文本的必要高度的方法:
NSSize newSize= NSMakeSize(width, 0.0);
NSLayoutManager* layoutManager= [[textStorage layoutManagers] objectAtIndex:0];
NSTextContainer* textContainer= [[layoutManager textContainers] objectAtIndex:0];
[textContainer setContainerSize:newSize];
[textStorage addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, [textStorage length])];
[textContainer setLineFragmentPadding:0.0];
[layoutManager glyphRangeForTextContainer:textContainer];
return [layoutManager usedRectForTextContainer:textContainer].size.height;
唯一的问题是我不知道如何使用布局管理器绘制 NSRect。
你能帮帮我吗? 提前致谢!
【问题讨论】:
标签: cocoa