在UITableview中创建一个固定格式的单元格

时间:2022-09-18 21:43:26

I want to have a tableview create rows that look like this:

我想要一个tableview来创建这样的行:

value1      item1     container1  
value10     item10    container10  
value100    item100   container100  
value2      item2     container2  

What I am trying to show is that the first word (value) will have a set length of 12 and then the second word (item) will have a set length of 10 and then the last word (container) is just tagged on at the end.

我要展示的是,第一个单词(value)的设置长度为12,第二个单词(item)的设置长度为10,然后最后一个单词(container)在末尾被标记。

I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted structure like this.

我正在从一个SQLite数据库中提取这些数据,不想使用多行数据,而是像这样以严格的格式进行读取。

2 个解决方案

#1


0  

You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)

你可以自定义布局UITableViewCell界面构建器,你将两个UILabel视图拖到内容查看和设置大小适当的(注意,信件可能不同的宽度,所以即使你知道这是10个字符长度,你不知道的最大宽度,请记住)

Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.

然后用另一个UILabel填充单元格右边的开放空间,将其布局为覆盖开放空间,并将其设置为自动调整其宽度,并将右边界设置为固定。

There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.

关于如何在tableView中使用自定义单元格,有很多教程可以参考,我可以向您推荐这个screencast。它解释了如何初始化自定义单元格,以及如何访问自定义标签。

#2


0  

It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.

听起来好像你想要一个老式的文本显示,那么第0行中的第n个字符总是在每行中排列第n个字符。

Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.

即使在自定义的tableviewcell中使用经过仔细定位的标签,如果希望所有字符在固定宽度列中对齐,也必须严格控制特定字体及其大小。您首先需要一个固定的宽度字体,并且您必须精确地设置大小。

You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.

您可能需要考虑这是否必要。iPhone用户被用来支持宽度文本显示。非常精确的文本列可能会使识别行变得困难。在调整列之前,我将首先使用一个简单的表进行测试。

#1


0  

You can layout a custom UITableViewCell in Interface Builder, where you drag two UILabel views onto the Content View and set their size appropriately (Notice that the letters may vary in width, so even though you know it's 10 chars in length, you don't know the maximum width, please keep that in mind)

你可以自定义布局UITableViewCell界面构建器,你将两个UILabel视图拖到内容查看和设置大小适当的(注意,信件可能不同的宽度,所以即使你知道这是10个字符长度,你不知道的最大宽度,请记住)

Then you just fill the open space at the right of a cell with another UILabel, layout it to cover the open space and set it to autoresize it's width and set the right margin to be fixed.

然后用另一个UILabel填充单元格右边的开放空间,将其布局为覆盖开放空间,并将其设置为自动调整其宽度,并将右边界设置为固定。

There are quite a few tutorials available on how to use the custom cell in your tableView, I can recommend you this screencast. It explains how you can initialize the custom cell and how you can access the custom labels.

关于如何在tableView中使用自定义单元格,有很多教程可以参考,我可以向您推荐这个screencast。它解释了如何初始化自定义单元格,以及如何访问自定义标签。

#2


0  

It sounds like you want something like an old-fashion text display in which then nth character in row zero always lines up the nth character in every row.

听起来好像你想要一个老式的文本显示,那么第0行中的第n个字符总是在每行中排列第n个字符。

Even using carefully positioned labels in a custom tableviewcell, you will have to strictly control the specific font and its size if you want all the characters to line up in fixed width column. You will need a fixed width font to begin with and you will have to set the size precisely.

即使在自定义的tableviewcell中使用经过仔细定位的标签,如果希望所有字符在固定宽度列中对齐,也必须严格控制特定字体及其大小。您首先需要一个固定的宽度字体,并且您必须精确地设置大小。

You might want to consider whether this is necessary. iPhone users are used to propionate width text displays. Very precise columns of text might make it difficult to discern rows. I would test first with just a simple table before spending the time tweaking the columns.

您可能需要考虑这是否必要。iPhone用户被用来支持宽度文本显示。非常精确的文本列可能会使识别行变得困难。在调整列之前,我将首先使用一个简单的表进行测试。