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)];
最終的に表示されるのは、長方形の下から上に向かっていくテキストです。ビューで描画すると、次のようになります。
熱心に。 物事を見る人はdif 四角い穴にペグを入れて、 トラブルメーカー、ルー 不適合、反逆者、 これがクレイジーな人たちです、
テキストを上から下に向かって開始し、テキストをワードラップする必要があります。今は、新しい行の単語の途中から開始します。、、、について読みましたがNSLayoutManager
、この問題を解決する方法がわかりません。NSParagraphStyle
NSTypeSetter