How to set top-left alignment for UILabel for iOS application?

后端 未结 21 1446
傲寒
傲寒 2020-12-04 07:54

I have added one label in my nib file, then its required to have top-left alignment for that lable. As I am providing text at runtime so its not sure that how much lines the

21条回答
  •  离开以前
    2020-12-04 08:11

    I was also having this problem but what I found was the the order in which you set the UILabel's properties and methods matters!

    If you call [label sizeToFit] before label.font = [UIFont fontWithName:@"Helvetica" size:14]; then the text does not align to the top but if you swap them around then it does!

    I also noticed that setting the text first makes a difference too.

    Hope this helps.

提交回复
热议问题