菜鸟教程小白 发表于 2022-12-12 15:05:57

ios - 在我的 UILabel(4 行)的子部分(2 行)上应用 lineBreakMode


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

<p>长篇大论:</p>

<p> <a href="http://img853.imageshack.us/img853/9436/iuha.jpg" rel="noreferrer noopener nofollow">Click here to see a screenshot of the App Store in iOS7.</a> </p>

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

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

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

<p>这是另一个例子。这是一个 UILabel:</p>

<pre><code>+------------------------------------------+
|                                          |
|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                                    |
|                                          |
+------------------------------------------|
</code></pre>

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

<pre><code>+------------------------------------------+
|                                          |
|                                          |
|Lorem ipsum dolor sit amet, consectetuer|
|adipiscing elit, sed diam nonummy nibh... |
|Line 2                                    |
|Line 3                                    |
|                                          |
|                                          |
+------------------------------------------|
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您需要创建自己的 UITableViewCell,向其中添加您想要的 View ,并将其添加到表格中。检查这个:</p>

<p> <a href="https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW18" rel="noreferrer noopener nofollow">Customizing UITableViewCells</a> </p>

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

<p>基本上,在配置 UILabel 时,您可以选择两个属性 lineBreakMode,它告诉您如何截断行和行数,但针对整个标签。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 在我的 UILabel(4 行)的子部分(2 行)上应用 lineBreakMode,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/19119969/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/19119969/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 在我的 UILabel(4 行)的子部分(2 行)上应用 lineBreakMode