Aleksander
Aleksander

Reputation: 2815

UILabel max height with AutoLayout

I have a multiline UILabel inside a custom keyboard extension. I want this label to grow to fill the content up to a certain height, at which point I want it to just cut off the rest of the text.

Because the keyboard has different heights depending on the device and orientation, I can't just set a simple less than or equal height constraint.

What I tried was to constrain the bottom of the label to the top of the buttons below, with a greater than or equal constraint. This works to a certain extent, but causes the keyboard to grow in size as opposed to the label being forced to cut off its text.

How would I force the label to a max height, without directly using a height constraint on the label?

Upvotes: 2

Views: 2841

Answers (1)

NRitH
NRitH

Reputation: 13893

Put the label in a UIView and constrain the view's height to less than or equal.

Upvotes: 1

Related Questions