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)];
我最终看到的是从矩形底部开始向上的文本。当我在视图中绘制它时,它看起来像这样:
热切地。 看东西的人不同 在方孔中找到钉子, 麻烦制造者,rou 格格不入者,叛逆者, 这是疯狂的人,
我希望文本从顶部开始向下,我还希望文本自动换行,现在它将在新行的单词中间开始。我阅读了关于NSLayoutManager
、NSParagraphStyle
和的信息NSTypeSetter
,但我不知道如何解决这个问题。