Align UILabel text in the lower left corner

I have a UILabel that sits on top of a UIImageView. The text can be of different lengths, so you need to make the label as large as possible (the same frame size as imageView). The problem is that I do not want the text from the label to cover the image, being directly in the center of the image. Easy to set left alignment in UILabel. Any clue how to set the vertical alignment as well? Basically, I want the text to hug the bottom left corner no matter how long it cuts.

+4
source share
1 answer

You can accomplish this with Autolayout. If you adjust your restrictions so that the label is fixed in the lower left corner, but do not set a height limit, Autolayout will use the Intrinsic Content Size label. This means that as the label gets more text / font / etc changes, the label will grow in height and only ever be tall enough to contain all the text in the label.

+17
source

Source: https://habr.com/ru/post/1546488/


All Articles