Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Get the "real" height of a letter

Tags:

ios

uifont

I am trying to layout text on a UIView.

(The yellow area is the frame of the UILabel with a background color).

When I use sizeWithFont I get this, which has a very large space above the letter:

p with sizeWithFont

When I use font.pointSize i get this for "i" which is good-

p with font.pointSize

BUT When i use it for "p" I get the precise height but the letter is drawn in the bottom and cropped.

p with font.pointSize

**How can i get get the glyph only centered in the frame ? **

Thanks

Shani

like image 979
shannoga Avatar asked Jan 26 '12 15:01

shannoga


1 Answers

There are a lot of properties on UIFont to help in this situation:

  • pointSize
  • ascender
  • descender
  • capHeight
  • xHeight
  • lineHeight
like image 120
Jeff Kelley Avatar answered Oct 01 '22 07:10

Jeff Kelley