iOS - 获取“真实”一封信的高度 [英] iOS - Get the "real" height of a letter

查看:120
本文介绍了iOS - 获取“真实”一封信的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆