1

我如何知道填充 NSTextField 正在使用的行片段?

4

1 回答 1

-1

您可以-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);
于 2012-07-21T11:26:01.160 回答