0

I have this UILabel in an app where the bottom of the text needs to (apppear to) rest on the edge of another uiview. The label also gets scaled by arbitrary amounts. The problem is that applying a scale to the label also scales the whitespace below the text in the label. So for instance scaling by 2.0f makes the whitespace twice as big, pushing the text farther away from the edge.

Is there a simple way of making a label perfectly fit the text's size so that the bottom pixel of the text is at the very bottom of the label view?

1 Answers1

0

Let me present you, the most useful method for these situations:

[myString sizeWithFont: ....];

This method (and its multiple variations) return the size that a NSString instance will use, therefore, you can scale the UILabel to your needs. iOS lacks a "Vertical Alignment" option.

Here is a similar stackoverflow question, if you're still in doubt.

Community
  • 1
  • 1
Can
  • 8,502
  • 48
  • 57
  • Thanks this got me on the right track. There was still whitespace, but apparently there is a property on UIFont called descender that gives the hight of the whitespace below the text, so I just adjusted the label frame origin.y by -descender. –  Aug 24 '11 at 15:14