OGeek|极客世界-中国程序员成长平台

标题: ios - 在我的 UILabel(4 行)的子部分(2 行)上应用 lineBreakMode [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:05
标题: ios - 在我的 UILabel(4 行)的子部分(2 行)上应用 lineBreakMode

简而言之:如何在 UILabel(比如 4 行)的子部分(比如 2 行)上应用 lineBreakMode。

长篇大论:

Click here to see a screenshot of the App Store in iOS7.

我有一个 4 行的 UILabel(红色)。我假设这是屏幕截图上的 UILabel,因为它们在每个 UITableViewCells 中都垂直居中。

此 UILabel 由一个子字符串组成,该子字符串最多被截断为 2 行(蓝色)。

在这个问题上花了一整天,我什至没有找到解决方案的开始。如果有人可以帮忙...

这是另一个例子。这是一个 UILabel:

+------------------------------------------+
|                                          |
|Lorem ipsum dolor sit amet, consectetuer  |
|adipiscing elit, sed diam nonummy nibh    |
|euismod tincidunt ut laoreet dolore magna |
|aliquam erat volutpat.                    |
|Line 2                                    |
|Line 3                                    |
|                                          |
+------------------------------------------|

我希望它以这种形式显示(第一句被截断为两行):

+------------------------------------------+
|                                          |
|                                          |
|Lorem ipsum dolor sit amet, consectetuer  |
|adipiscing elit, sed diam nonummy nibh... |
|Line 2                                    |
|Line 3                                    |
|                                          |
|                                          |
+------------------------------------------|



Best Answer-推荐答案


您需要创建自己的 UITableViewCell,向其中添加您想要的 View ,并将其添加到表格中。检查这个:

Customizing UITableViewCells

正如你所说,你想要实现的目标似乎相当复杂,至少如果没有 CoreText 是不可能的(并且不确定是否可能)。

基本上,在配置 UILabel 时,您可以选择两个属性 lineBreakMode,它告诉您如何截断行和行数,但针对整个标签。

关于ios - 在我的 UILabel(4 行)的子部分(2 行)上应用 lineBreakMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19119969/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4