cocoa - NSTextField 的 LineFragmentPadding

标签 cocoa nstextfield

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

最佳答案

您可以将-lineFragmentPadding用于NSTextField的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/

相关文章:

objective-c - CGContextDrawImage 泄漏

objective-c - 在 NSTableView 中创建自定义单元格

swift - 如何在 OS X 上的文本字段上使用 DidEndEditing (swift)

nstextfield - 运行macruby时没有输入到NSTextField

objective-c - 在 NSTextField 中发送值 : objective c

macos - NSTextView 监听插入符位置变化

objective-c - 观察派生属性的变化: CALayer KVO example

cocoa - NSOutlineView 检测子项何时折叠

objective-c - NSTextView 设置格式器?

objective-c - NSButton 没有响应