我怎么知道填充NSTextField的行片段?

最佳答案

您可以将-lineFragmentPadding用于NSTextField's textContainer。像这样:

float lineFragmentPadding = [textContainer lineFragmentPadding];


例如:

NSSize textFieldSize = [textFieldOutlet frame].size;
NSTextStorage *textStorage = [[[NSTextStorage alloc] initWithAttributedString:[textFieldOutlet attributedStringValue]] autorelease];
NSTextContainer *textContainer = [[[NSTextContainer alloc] initWithContainerSize:NSMakeSize(textFieldSize.width, textFieldSize.height)] autorelease];
NSLayoutManager *layoutManager = [[[NSLayoutManager alloc] init] autorelease];

[layoutManager addTextContainer:textContainer];
[textStorage addLayoutManager:layoutManager];

[layoutManager glyphRangeForTextContainer:textContainer];

float lineFragmentPadding = [textContainer lineFragmentPadding];
NSLog(@"Padding: %f", lineFragmentPadding);

关于cocoa - NSTextField的LineFragmentPadding,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11587162/

10-15 11:58