Reputation: 25
Using Xcode 5, interface builder and developing for iOS 7.
Within my content view I have 2 additional sub views, one on top of another. Within the upper subview I have a UILabel
. I would like for that UILabel
to expand in height when the content exceeds the first line, but I can't seem to get the height increase of the UILabel
to increase the height of the subview, thus pushing the bottom subview down the main content view.
Additionally, I would assume the content view would need some sort of a constraint that reflects the overall height of the two subviews?
Perhaps this the question has already been answered somewhere, but I've searched everywhere and can't seem to come up with a solution.
Any help would be hugely appreciated! Thanks in advance.
Upvotes: 1
Views: 707
Reputation: 40038
There is a couple of steps that you have to do to achieve this using autolayout
.
height
constraint with low priority. numberOfLines
to 0
to allow multiline text.preferredMaxLayoutWidth
for the label. The preferredMaxLayoutWidth
is used by label to calculate its height.
This property affects the size of the label when layout constraints are applied to it. During layout, if the text extends beyond the width specified by this property, the additional text is flowed to one or more new lines, thereby increasing the height of the label.
Also, have a look here.
Upvotes: 2