gpt4 book ai didi

objective-c - NSLayoutManager Text 新行似乎从矩形底部开始向上

转载 作者:行者123 更新时间:2023-12-03 16:38:49 26 4
gpt4 key购买 nike

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)];

我最终看到的是从矩形底部开始向上的文本。当我在 View 中绘制它时,它看起来像这样:

ferently.the ones who see things difnd pegs in the square holes, the troublemakers, the rou the misfits, the rebels,Here's to the crazy ones,

我希望文本从顶部开始向下,并且我还希望文本自动换行,现在它将在新行上从单词的中间开始。我阅读了有关 NSLayoutManagerNSParagraphStyleNSTypeSetter 的内容,但我不知道如何解决此问题。

最佳答案

重写 isFlipped 以在 NSView 子类中返回 YES。

关于objective-c - NSLayoutManager Text 新行似乎从矩形底部开始向上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6403796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com