iOS - 获取“真实”一封信的高度 [英] iOS - Get the "real" height of a letter
问题描述
我正在尝试在UIView上布局文本。
I am trying to layout text on a UIView.
(黄色区域是具有背景颜色的UILabel的框架)。
(The yellow area is the frame of the UILabel with a background color).
当我使用sizeWithFont时,我得到了这个,它在字母上面有一个非常大的空间:
When I use sizeWithFont I get this, which has a very large space above the letter:
当我使用 font.pointSize
我为i得到这个好 -
When I use font.pointSize
i get this for "i" which is good-
但是
当我用它作p时,我得到了精确的高度,但字母在底部绘制并裁剪。
BUT When i use it for "p" I get the precise height but the letter is drawn in the bottom and cropped.
**如何才能获得仅在帧中居的字形? **
**How can i get get the glyph only centered in the frame ? **
谢谢
Shani
推荐答案
UIFont
在这种情况下提供帮助:
There are a lot of properties on UIFont
to help in this situation:
-
pointSize
-
ascender
-
descender
-
capHeight
-
xHeight
-
lineHeight
pointSize
ascender
descender
capHeight
xHeight
lineHeight
这篇关于iOS - 获取“真实”一封信的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!