- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一整天都在寻找这个问题的解决方案。
我有 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 引用:
这是文本布局教程中的页面:
在那篇文章中指出:
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.
不幸的是,它看起来像 NSTextField
的 NSTextContainer
和 NSLayoutManager
是私有(private)的并且无法访问,但看起来它们可以在 中访问>NSTextView
:
因此,如果您想对此类功能进行精细控制,那么这可能是您需要子类化的类。
关于objective-c - NSTextField 奇怪的左边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13825867/
我有 NSTextField 但我必须显示的内容不是固定的,它会动态增长。有什么简单的方法可以动态改变大小。提前致谢:) 最佳答案 文本字段的委托(delegate)需要随着文本的变化而更新大小。 诀
我正在尝试实现一个自定义的NSTextField,它a)在事件时改变颜色,b)在左上角有一个标签。 我有以下实现: 在TestTextField.h @interface TestTextField
我有大约 10 个按钮,每个按钮都有不同的名称。在选择每个按钮时,我需要将按钮的标题附加到 NSTextField,而不删除旧字符串。 我试过以下方法。 - (IBAction)nextButton:
我有一个 NSSlider,它可以更新 NSTextField 的内容。到目前为止,一切都很好。只要 NSTextField 没有聚焦或被用户编辑(键入或保持空白等),它就可以工作。 我想要做的是通过
我在从不同类中的 NSTExtField 访问值时遇到问题,这里是代码: AppDelegate.h #import @interface AppDelegate : NSObject @prop
我正在制作一个登录页面,当我得到用户输入时它很好。凭据将存储在一个文件中。存储在文件中的值被设置为 NSTextField 的字符串。 . 如果我使用 NSSecureTextField当我从文件中读
我正在尝试在其窗口委托(delegate)中访问 NSTextField 实例的复制、剪切和粘贴方法,以便我可以自定义这些方法。我发现与 tableViews 和 textViews 不同,文本字段的
我正在尝试创建一个 NSTextField 以允许批量重命名某些文件。该字段应该允许插入一些标记来自定义每个文件名。 NSTokenField 的问题在于 1)它会修剪空白,这是应该允许的,2)它没有
我的 XIB 文件中有一个文本字段标签,用于显示我想要动态加载的一些文本。这是我的应用程序的当前流程: -在 XIB 文件中,文本字段设置为静态文本- 运行应用程序时,窗口会加载文本字段和静态文本-加
我的应用程序有 NSTextFields 用于输入;我故意不使用 NSNumberFormatter 来对输入进行特殊处理。该应用程序实现“全屏”模式。当应用程序处于全屏状态并且焦点位于文本字段中时,
我有一个 NSTextField 的自定义子类。我想在右键单击时显示上下文菜单,但该菜单显示完全不相关的服务菜单。我知道这是由于操作系统设置而添加的,但这些选项在我的场景中根本没有用(例如,文本字段包
我如何知道 NSTextField 何时获得焦点? 是否有一个委托(delegate)方法可以告诉我用户何时在我的 NSTextField 中单击鼠标(或以其他方式选择)? 谢谢 汤姆 最佳答案 子类
我有一个 NSTextField 和 Label,其值绑定(bind)到 View Controller 中的相同 NSString 这里的问题是标签只有在我按 Tab 时才会更新。 如何使其连续,以
我之前设置过,但现在找不到这个选项了... alt text http://www.joelsaltzman.com/pics/ib.png 最佳答案 当您使用绑定(bind)连接文本字段时,该选项可
我的 NSTextField 子类遇到一些问题。这是一个用于输入一些消息的文本字段。当我的子文本字段是第一响应者并且用户按下热键 Cmd + Enter 时,我的应用程序必须发送此消息。我无法使用 C
如何在 NSTextField 的左侧添加搜索图标?您可以在许多其他应用程序中看到同样的情况。 最佳答案 我猜是这样的: text = NSTextField.alloc().initWithFram
我正在使用两个 NSTextFields 作为用户名和密码。通常它工作正常,但有时当我切换出用户名文本字段时,用户名中的文本消失,但字符串值仍然存在。当我切换回“用户名”文本字段时,该文本会重新出现,
当我使用时 [myNSTextField setStringValue:@"AAA"]; 设置 NSTextField 的文本 文本始终具有黑色背景,看起来像是已被选中。是否可以显示黑色文本颜色和白色
我正在尝试使用 NSTextField 制作一个简单的动画 - (void)bounceTimeLabel { // Create a key frame animation C
我得到了一个 NSTextField,它看起来很好,直到它放弃了第一个响应者。 它会绘制一个白色矩形,直到再次成为第一响应者。知道如何避免这种情况吗? 最佳答案 绘图问题似乎是由 TextField
我是一名优秀的程序员,十分优秀!