Forum Archive

How do I vertically align text within a label?

offtheradar

When creating a label with the frame attribute set, how can the vertical alignment of text be set within the height of the label? I want the text top aligned not center which appears to be the default.

Thanks!

omz

There is no way to change the vertical alignment of a ui.Label, but you could achieve a similar effect using my_label.size_to_fit().

Phuket2

@offtheradar , you could also add your label as a subview of another view. Depending on want you are trying to achieve, could give you more control. It sounds a little over the top, but I dont think it is. Just a though

offtheradar

Thanks @omz & @Phuket2. my_label.size_to_fit() worked to achieve the alignment I wanted.