ios 中字体大小的真正含义是什么?

What does font size really mean in ios?

似乎字体大小并不能决定任何事情。

这里有两行,一行使用字体zapfino,另一行使用system font。它们的大小都是 30,但行高或其他字体指标确实不同。

这张图是用YYLabel绘制的,使用coretext布局绘制文字,使用这个框架我们可以很容易地看到一个字形的边框。

下面是另一张图片,使用两个不同字体的 UILabel 并在 StroyBoard 中预览。

那么布局一行时coretext中的字体大小是什么意思?

来自 the Wiki page 点(排版)

When a point size of a font is specified, the font is scaled so that its em square has a side length of that particular length in points. Although the letters of a font usually fit within the font's em square, there is not necessarily any size relationship between the two, so the point size does not necessarily correspond to any measurement of the size of the letters[.]

因此,在所有数字字体中,除了字体设计师选择在其上设计其字形的假想正方形之外,字体大小与任何其他内容都没有真正的关联。所以有时这会与大写字母 M 的宽度相关,但并非总是如此。你提到的 Zapfino 字体是完全超出其边界框的更大胆的例子之一。这里它与 Helvetica 相邻,点大小相同:

尽管它们具有相似的 X 高度,但 Zapfino 的 cap-height、ascenders 和 descenders 是如此之大,以至于大多数渲染引擎(包括 CoreText)中每个字母的单元格高度将是 Helvetica 的两倍以上。这就是字体的设计方式。你要么需要根据你使用的字体手动调整你的字体大小,要么尝试像 this one.

这样的编程方法

祝你好运!