用于NSTextField的LineFragmentPadding

时间:2012-07-20 21:27:55

标签: cocoa nstextfield

我怎么知道NSTextField使用的线段填充?

1 个答案:

答案 0 :(得分:0)

您可以将-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);