繁体   English   中英

表格视图单元格的多行详细文本标签

[英]Multiple lines in detail text label of table view cell

我试图在单元格的 detailTextLabel 中有多行,但每行都有离散信息。 为了在 detailTextLabel 中获得多行,我会使用

cell.detailTextLabel?.numberOfLines = 0
cell.detailTextLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping

但我希望每一行都有特定的文字。 我知道 swift 没有换行符,所以我相信它必须看起来像这样:

 cell.detailTextLabel!.text = "Line 1" +
                        "Line 2" +
                        "Line 3" +
                        "Line 4" +
                        "Line 5"

但这会在 detailsTextLabel 中返​​回 Line1Line2Line3Line4Line5。

我可以通过放入一个超长的字符串并将它包装成多行来成功地有多行。

有没有简单的方法来实现这一点? 或者只是不可能?

感谢 Shoaib,您所要做的就是在字符串中实现 "\\n"

cell.detailTextLabel!.text = "Line 1" + "\n" + "Line 2" + "\n" + "Line 3" + "\n" + "Line 4" + "\n" + "Line 5"

您可以使用多行字符串格式,例如:

cell.detailTextLabel!.text = """
Line 1
Line 2
Line 3
Line 4
Line 5
"""

诡计

如果您想在多个项目之间添加类似的内容(如@Tamarisk 答案),您可以从以下数组中获得帮助:

[
    "Line 1",
    "Line 2",
    "Line 3",
    "Line 4",
    "Line 5",
].joined(separator: "\n")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM