右对齐的 UILabel 对象文本略有偏差

发布于 2024-11-19 22:45:14 字数 602 浏览 5 评论 0原文

我目前对 UILabel 对象有一个小问题。在 Xcode 4.0.2 中,我使用 Interface Builder 构建一个视图,其中包含一些垂直堆叠的右对齐标签。除了标签和框架的 Y 坐标外,标签均相同。

如果标签中的文本长度都相同,则文本的权利会很好地排列在一起。然而,如果文本长度不同,较长文本的权利会略有偏差。如果我更改 IB 中的文本属性并在设计图面上观察它,或者如果我在模拟器或设备上运行应用程序并且标签中的文本长度不同,都会发生这种情况。为了更清楚地观察这一点,我更改了几个标签的背景颜色,一旦文本长度不同,它就立即可见。

我尝试将标签的许多属性更改为相同,我增加了标签的大小,但似乎没有什么影响这一点。标签的宽度远远大于我试图放入其中的文本。

这是我正在谈论的一个例子。在 IB 中,所有标签具有相同文本长度的视图如下所示:

在此处输入图像描述

以及如果我将第一个标签的文本更改为 00.00,情况如下:

在此处输入图像描述

有关可能的任何想法造成这个?

I am currently having a minor issue with UILabel objects. In Xcode 4.0.2, I am using Interface Builder to build a view with some right aligned labels stacked vertically. The labels are all identical except for their tag and for the Y coordinates of their frame.

If the text in the labels are all the same length, the rights of the text are happily lined up. However, if the text length is different, the rights of the longer text will be off slightly. This happens both if I change the text property in IB and observe it on the design surface, and if I run the app in either the simulator or on the device and have differing text lengths in the labels. In order to more clearly observe this, I changed the background color of a couple of the labels, and it is visible right away once the text lengths are different.

I have tried to change a lot of the properties of the labels to be the same, I have increased the size of the labels, but nothing seems to affect this. The width of the label is far larger than the text that I am trying to place inside.

Here is an example of what I am talking about. In IB, here is what the view looks like with all of the labels having the same text length:

enter image description here

And here is what it looks like if I change the first label's text to 00.00:

enter image description here

Any ideas of what could be causing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2024-11-26 22:45:14

我相信原因是因为单词中的第一个字符的 x 位置与整数坐标对齐,但后续字符使用小数 x 位置(以便提供均匀的字距调整)。通过在第一行添加一个额外的零,您已经更改了单词的开始位置,因此行中最后一个零的小数位置与其他零略有不同。

老实说,我不会担心这个。这是一个非常微妙的抗锯齿差异。

I believe the reason is because the first character in a word has its x position aligned to integral coordinates, but subsequent characters use the fractional x position (so as to provide for even kerning). By adding an extra zero to the first line, you've changed where the word starts, and so the last zero in your line is at a slightly different fractional position than the other zeros.

Honestly, I wouldn't worry about it. It's a very subtle antialiasing difference.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文