gpt4 book ai didi

objective-c - NSTextField 奇怪的左边距

转载 作者:行者123 更新时间:2023-12-03 17:28:21 26 4
gpt4 key购买 nike

我一整天都在寻找这个问题的解决方案。

我有 4 个 NSTextField(实际上是一些自定义操作的子类),它们都共享相同的 X 位置。

问题是,有些有不同的样式(浅色、常规、粗体)并且可能有不同的尺寸。

发生的情况是,即使 X 原点相同,第一个字母总是有一些(始终不同的)左边距。

请看图:https://dl.dropbox.com/u/1977230/Screen%20Shot%202012-12-11%20at%2017.55.58.png

我想确保所有线条都从同一点开始,比如距左侧 100 像素。

知道如何覆盖那个奇怪的填充吗?

干杯

最佳答案

我很确定你所说的边距是 NSTextField 使用的 NSTextContainer 上的 lineFragmentPadding

查看 NSTextContainer 引用:

http://developer.apple.com/library/Mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextContainer_Class/Reference/Reference.html

这是文本布局教程中的页面:

https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/TextLayout/Concepts/CalcTextLayout.html

在那篇文章中指出:

The typesetter makes one final adjustment when it actually fits text into the rectangle. This adjustment is a small amount fixed by the NSTextContainer object, called the line fragment padding, which defines the portion on each end of the line fragment rectangle left blank. Text is inset within the line fragment rectangle by this amount (the rectangle itself is unaffected). Padding allows for small-scale adjustment of the text container’s region at the edges and around any holes and keeps text from directly abutting any other graphics displayed near the region. You can change the padding from its default value with the setLineFragmentPadding: method. Note that line fragment padding isn’t a suitable means for expressing margins; you should set the NSTextView object’s position and size for document margins or the paragraph margin attributes for text margins.

不幸的是,它看起来像 NSTextFieldNSTextContainerNSLayoutManager 是私有(private)的并且无法访问,但看起来它们可以在 中访问>NSTextView:

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html#//apple_ref/occ/cl/NSTextView

因此,如果您想对此类功能进行精细控制,那么这可能是您需要子类化的类。

关于objective-c - NSTextField 奇怪的左边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825867/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com