Colin
Colin

Reputation: 4135

Multi-line label of unlimited size with the text top-aligned?

I haven't been able to figure it out and most of the techniques coming up in Google have been deprecated:

I want to have a multi-line label of unlimited size with the text top-aligned.

How do I do it?

Upvotes: 0

Views: 199

Answers (1)

If you don't add constraints in your Interface Builder or in code, the view will use it's "default" size in the Interface Builder.

Set the numberOfLines of the label to 0. Pin constraints in your Interface Builder from the label's top to it's superview + left and right of the label to it's superview.

Then the label grows with it's content as long as needed. You can also add a bottom constraint to the label with a >= X value which limits the label also in it's height when you want to have a max height.

Upvotes: 1

Related Questions