How to set the UILabel text to be top aligned

I am having trouble in setting the text of a UILabel's text to be top aligned.

I have read some answers in stackoverflow and I tried: Vertically align text to top within a UILabel

self.label.text = @"Hello world";
[self.label setNumberOfLines:0];
[self.label sizeToFit];

The label's height is 67 pixel long. But when I run it, the text is vertically centered in the label. So how can I make it to top aligned?


You could just use AutoLayout to constrain the vertical position of the label. For example, you could pin the top edge of the label to the top of the superview or something.

链接地址: http://www.djcxy.com/p/28264.html

上一篇: 使用SizeToFit()顶部对齐UILabel会导致跳转

下一篇: 如何将UILabel文本设置为顶部对齐