开发者

Creating a fixed formatted cell in UITableview

开发者 https://www.devze.com 2022-12-15 09:50 出处:网络
I want to have a tableview create rows that look like this: value1item1container1 value10item10container10

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

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.

I am pulling these from a SQLite database and don't want to use multiple lines, but read in a strictly formatted st开发者_运维问答ructure like this.


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)

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.

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.


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.

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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号