简体   繁体   中英

Align UILabel Text to bottom left corner

I have a UILabel that is positioned on top of a UIImageView. The text can be various lengths, so it is necessary that I make the label as large as possible (The same size frame as the imageView). The problem is, I don't want the text from the label to cover the image by being directly in the center of the image. It's easy to set left alignment in a UILabel. Any clue how to set vertical alignment as well? Basically I want the text to hug the bottom left corner no matter what length it is without being cut off.

You can accomplish this with Autolayout. If you set up your constraints so that the label is fixed to the bottom left, but don't set a height constraint, Autolayout will use the label's Intrinsic Content Size. This just means that as the label gets more text / changes font / etc, the label will grow in height and will only ever be tall enough to contain all the text in the label.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM