NSLayoutManager Текст, новая строка, кажется, начинается снизу прямоугольника и идет вверх - PullRequest
2 голосов
/ 19 июня 2011
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, но не могу понять, как решить эту проблему.

1 Ответ

2 голосов
/ 19 июня 2011

Переопределить isFlipped, чтобы вернуть YES в вашем подклассе NSView.

...