UILabel和UIButton - 截断标签而不是按钮

时间:2017-09-29 09:53:43

标签: ios xcode uibutton truncate xcode9

在我的应用程序中,我有一个带有自定义单元格的UITableView,其中包含动态标题标签和旁边的按钮,如下面的屏幕截图所示:

my custom cell

我的问题是当Title标签太长时,按钮会被截断。

相反,我希望标签被截断,按钮应始终完全显示。我怎样才能做到这一点?

(我不想为按钮设置固定宽度,因为也必须支持国际化)

2 个答案:

答案 0 :(得分:1)

labelbutton之间约束的优先级设置为250(低)。并设置另一个约束,即从标题标签到superview的尾随空格,它应该比按钮的宽度稍微大一些。希望它可以帮到你。

答案 1 :(得分:1)

1)将固定宽度设置为button

注意:在这种情况下,该按钮会被截断

2)将固定宽度设置为label

如果您将固定宽度设置为label,则iPad的宽度会相同,所以看起来非常难看

enter image description here

您需要根据UIScreen管理宽度,如果您将固定宽度设置为label

3)使用Content hugging priorityContent compression resistance priority

  • label

    设置以下约束

    Content hugging priority和749 in中设置水平250 Content compression resistance priority

    enter image description here

相关问题