问题
I have a UITableViewCell
with two UILabel
s: 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.
Set number of lines to '0' in the Utilities pane > Attributes inspector.
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.
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