自动布局:没有的UILabel与长文本适当调整 [英] Autolayout: UILabel not resizing properly with long text

查看:163
本文介绍了自动布局:没有的UILabel与长文本适当调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableViewCell有两个的UILabel,标题和说明。

I have a UITableViewCell with two UILabel, title and description.

我有标题标签的问题。基本上,我要的是增加它的高度,如果文本大于可用空间和prevent的...做大。这是它的外观,你可以在右侧看到标题标签的约束。

I am having problems with the title label. Basically, what I want is to increase it's height if the text is bigger than the available space and prevent the "...". This is how it looks, you can see the constrains of the title label on the right.

正如你所看到的,标题标签,成功提升它的高度,但在一行文字依然。在 - 标注文本样式中使用的字体。有什么建议?

As you can see, the title label successfully increase it's height but the text still in one line. The font used in "Text Styles - Callout". Any suggestions?

修改1 :我已经设置的行数为0

Edit 1: I already set number of lines to '0'

编辑2 :我固定通过删除的UILabel,然后重新添加,而是先来看看由WOJTEK提出的建议

Edit 2: I fixed by deleting the UILabel and adding it again, but first take a look at suggestions made by Wojtek.

推荐答案

此行​​为是在支持与自动布局,通过以下步骤有问题的UILabels。

This behavior is supported with Auto-layout on, by following these steps for the UILabels in question.


  1. 在设置实用程序面板线为'0'的数量>属性检查器。

  1. Set number of lines to '0' in the Utilities pane > Attributes inspector.

右键单击的UILabel和Alt - 控制(X code 7.1及以上)拖动到它的上海华设置前置,顶部和底部边距

Right click the UILabel and Alt - control (Xcode 7.1 and above) drag to it's superview to set the leading, trailing, top and bottom margin.

和对于自动高度宽度可以设置约束与关系级别600的优先级。大于或等于

For auto height and width you can set the priority of the constraint to level '600' with relation 'Greater than or Equal'.

Github上的例子(我只用在下面的例子中底部约束不同的'关系'你也可以选择一个不同的约束条件,即在特定的情况下,尾随约束做到这一点。)的 https://github.com/wojtekdmyszewicz/UILabel

Github example (I only use a different 'relation' for the bottom constraint in the following example. You could also choose to do this for a different constraint i.e. the trailing constraint in your specific case): https://github.com/wojtekdmyszewicz/UILabel

在这里输入的形象描述

这篇关于自动布局:没有的UILabel与长文本适当调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆