How to align UILabel text from bottom?

后端 未结 10 1688
盖世英雄少女心
盖世英雄少女心 2021-02-03 19:08

How the UILabel can be aligned from bottom. Let say, my label can hold three line of text.If the input text is single line, then this line should come bottom of the

10条回答
  •  感动是毒
    2021-02-03 20:03

    Another option: use one label for your background color, I call this one originalLabel, and another for the text, called textLabel in my example. Then calculate the height and Y coordinate for textLabel:

    [textLabel sizeToFit];
    int height = textLabel.frame.size.height;
    int yCoord = originalLabel.frame.origin.y + 
              originalLabel.frame.size.height - height;
    textLabel.frame = CGRectMake( originalLabel.frame.origin.x, yCoord,
              textLabel.frame.size.width, height);
    

提交回复
热议问题