Autolayout: UILabel not resizing properly with long text

那年仲夏 提交于 2020-01-15 05:40:49

问题


I have a UITableViewCell with two UILabels: title and description.

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

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

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

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


回答1:


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

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

  2. 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.

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

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



来源:https://stackoverflow.com/questions/34009311/autolayout-uilabel-not-resizing-properly-with-long-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!