NSLayoutManager Text 新行似乎从矩形底部开始向上
m_LayoutManager = [[NSLayoutManager alloc] init];
m_TextContainer = [[NSTextContainer alloc] init];
m_TextStorage = [[NSTextStorage alloc] initWithString: @"Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes, the ones who see things differently."];
[m_LayoutManager addTextContainer: m_TextContainer];
[m_TextStorage addLayoutManager: m_LayoutManager];
[m_TextContainer release];
[m_LayoutManager release];
[m_TextStorage replaceCharactersInRange:NSMakeRange(0, [m_TextStorage length]) withString: XMajor];
[m_TextContainer setContainerSize: NSMakeSize(75,50)];
NSRange glyphRange = [m_LayoutManager glyphRangeForTextContainer: m_TextContainer];
NSRect usedRect = [m_LayoutManager usedRectForTextContainer: m_TextContainer];
[[NSColor brownColor] setFill];
//NSRectFill( NSMakeRect(j - usedRect.size.width/2,y0 - 50 - 5,50,50));
[m_LayoutManager drawGlyphsForGlyphRange:glyphRange
atPoint: NSMakePoint(j - usedRect.size.width/2,y0 - 50 - 5)];
我最终看到的是从矩形底部开始向上的文本。当我在视图中绘制它时,它看起来像这样:
ferently. the ones who see things dif nd pegs in the square holes, the troublemakers, the rou the misfits, the rebels, Here's to the crazy ones,
我希望文本从顶部开始向下,并且我还希望文本自动换行,现在它将在新行上从单词的中间开始。我阅读了有关 NSLayoutManager
、NSParagraphStyle
和 NSTypeSetter
的内容,但我不知道如何解决此问题。
m_LayoutManager = [[NSLayoutManager alloc] init];
m_TextContainer = [[NSTextContainer alloc] init];
m_TextStorage = [[NSTextStorage alloc] initWithString: @"Here's to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes, the ones who see things differently."];
[m_LayoutManager addTextContainer: m_TextContainer];
[m_TextStorage addLayoutManager: m_LayoutManager];
[m_TextContainer release];
[m_LayoutManager release];
[m_TextStorage replaceCharactersInRange:NSMakeRange(0, [m_TextStorage length]) withString: XMajor];
[m_TextContainer setContainerSize: NSMakeSize(75,50)];
NSRange glyphRange = [m_LayoutManager glyphRangeForTextContainer: m_TextContainer];
NSRect usedRect = [m_LayoutManager usedRectForTextContainer: m_TextContainer];
[[NSColor brownColor] setFill];
//NSRectFill( NSMakeRect(j - usedRect.size.width/2,y0 - 50 - 5,50,50));
[m_LayoutManager drawGlyphsForGlyphRange:glyphRange
atPoint: NSMakePoint(j - usedRect.size.width/2,y0 - 50 - 5)];
What I end up seeing is the text starting from the bottom of the rectangle and going up. It looks like this when I draw it in view:
ferently. the ones who see things dif nd pegs in the square holes, the troublemakers, the rou the misfits, the rebels, Here's to the crazy ones,
I want the text to start from top and go down and I also want the text to word wrap, right now it will start the middle of a word on a new line. I read about NSLayoutManager
, NSParagraphStyle
, and NSTypeSetter
, but I cannot figure out how to fix this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
覆盖
isFlipped
以在 NSView 子类中返回 YES。Override
isFlipped
to return YES in your subclass of NSView.