无论字母大小如何,都将字母均匀分布在标签上

发布于 2024-11-04 21:00:32 字数 391 浏览 2 评论 0原文

我正在尝试编写我的第一个 iOS 程序,我需要显示一个字母矩阵并单独移动其垂直线,因为这个字母矩阵比屏幕本身大。

我希望这些字母在水平和垂直方向上均匀分布,无论实际字母是什么。 iy 具有不同的宽度,ob 具有不同的高度。我正在寻找的是一个表格,每个字母占据一个单元格。

首先,我选择 UILabel 来显示各个垂直线,因为这样我就可以为这些线设置动画。然而,标签上的字母分布并不均匀。

有没有办法告诉 UILabel 中的各个字母占据 x 宽度,而不管实际字母的宽度如何?

iOS 中是否有更好的控件或视图来构建字母矩阵,并且仍然能够单独移动其垂直线?

I am trying to write my first iOS program and I need to display a matrix of letters and move its vertical lines separately because this matrix of letters is larger than the screen itself.

I would like these letters to be evenly spaced both in horizontal and vertical directions regardless what the actual letter is. i and y have different widths and o and b have different heights. What I am looking for is to have a table and each letter occupies a single cell.

First, I choose UILabel to display the individual vertical lines, because this way I can animate the lines. However, with the labels the letters are not distributed evenly.

Is there a way to tell the individual letters in a UILabel to occupy x amount of width regardless of the width of an actual letter?

Is there a better control or view in iOS to construct a matrix of letters and still be able to move its vertical lines separately?

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

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

发布评论

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

评论(3

埋葬我深情 2024-11-11 21:00:32

非常快速的答案:使用固定宽度的字体,例如 Courier,它使所有字母的间距相等。

Very quick answer: Use a fixed width font, like Courier, which spaces all letters equally.

笨死的猪 2024-11-11 21:00:32

您绝对应该考虑一种编程方式。如果您使用界面生成器执行此操作,那么您所做的正是它不该做的事情:昂贵的点击冒险!

只需创建一个特定大小的 UILabel,创建下一个、下一个、下一个、下一个,然后移动到下一行。我希望不必向您解释它是如何工作的。请记住,您是在 loadView 中创建它们的!!!! ^^

You should definetly think about a programmatic way. If you do this with interface-builder you do exactly what it is not meant for: Expensive point and click adventures!

Just create a UILabel within a specific size, create the next, next, next, next, and then you move to the next line. I hopefully don't have to explain to you how that works. And keep in mind, that you create them in loadView !!!! ^^

○闲身 2024-11-11 21:00:32
  • 为每个字母创建一个 UILabel
  • 使所有标签具有相同的宽度和高度
  • 设置 textAlignment 到 UITextAlignmentCenter
  • 将它们均匀分布在网格中
  • Create one UILabel for each letter
  • Make all labels the same width and height
  • Set textAlignment to UITextAlignmentCenter
  • Distribute them evenly in your grid
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文