无论字母大小如何,都将字母均匀分布在标签上
我正在尝试编写我的第一个 iOS 程序,我需要显示一个字母矩阵并单独移动其垂直线,因为这个字母矩阵比屏幕本身大。
我希望这些字母在水平和垂直方向上均匀分布,无论实际字母是什么。 i 和 y 具有不同的宽度,o 和 b 具有不同的高度。我正在寻找的是一个表格,每个字母占据一个单元格。
首先,我选择 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
非常快速的答案:使用固定宽度的字体,例如 Courier,它使所有字母的间距相等。
Very quick answer: Use a fixed width font, like Courier, which spaces all letters equally.
您绝对应该考虑一种编程方式。如果您使用界面生成器执行此操作,那么您所做的正是它不该做的事情:昂贵的点击冒险!
只需创建一个特定大小的 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 !!!! ^^