问题描述
UITableView单元格有多行的最佳方法是什么?让我们说5 ..或6?
What's the best way to have UITableView cells with multiple lines ? Let's say 5.. or 6 ?
而不是textLabel和la detailTextLabel?我应该创建自定义样式吗?或自定义视图?
Instead of textLabel and la detailTextLabel ? Should I create a custom style ? or a custom view ?
任何教程/示例都被广泛接受。
Any tutorial / example is well accepted.
谢谢
推荐答案
您可以在UITableViewCell中使用现有的UILabel视图。秘诀是执行以下操作:
You can use the existing UILabel views in the UITableViewCell for this. The secret is to do the following:
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
默认情况下,UILabel只允许1行文本。将numberOfLines设置为0基本上可以消除对显示的行数的任何限制。这允许你有多行文本。
By default, the UILabel only allows 1 line of text. Setting numberOfLines to 0 basically removes any limitations on the number of lines displayed. This allows you to have multiple lines of text.
lineBreakMode到Word Wrap的设置告诉它将长行文本换行到标签的下一行。如果您不想这样,可以跳过该行。
The setting of the lineBreakMode to Word Wrap tells it to word wrap long lines of text onto the next line in the label. If you don't want this, you can skip that line.
您可能还需要根据需要调整表格视图单元格的高度,以便为您添加的多行文字。
You may also have to adjust the height of the table view cell as needed to make more room for the multiple lines of text you add.
对于iOS 6.0及更高版本,请使用 NSLineBreakByWordWrapping
而不是 UILineBreakModeWordWrap
,已弃用。
For iOS 6.0 and later, use NSLineBreakByWordWrapping
instead of UILineBreakModeWordWrap
, which has been deprecated.
这篇关于iOS:具有多行的UITableView单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!