字体大小(以像素为单位) [英] Font size in pixels

查看:55
本文介绍了字体大小(以像素为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iPhone 上,如何计算给定点大小的字符大小(以像素为单位)?

On an iPhone how do I calculate the size of a character in pixels for a given point size?

推荐答案

点大小 定义为 1/72 英寸.也就是说,72 号字体从最低下降到最高上升大约为 1 英寸.因此,72pt 字体中字形的最大高度约为 1 英寸.

Point sizes are defined as 1/72 of an inch. That is, a 72-point font is approximately 1 inch from the lowest descent to the highest ascent. So the maximum height of a glyph in a 72pt font is about 1 inch.

Apple 的 iphone 技术规格页面声称 iPhone 目前 具有每英寸 163 像素的分辨率.所以 72 点是 163 像素,或者每点大约 2.2639 像素.请记住,每个字形的高度和宽度都不同,因此这是对大小的非常粗略的估计.通常,基线 之间的距离会比字体的磅值大一点,因此文本行不会相互碰撞.

Apple's iphone tech specs page claims that the iPhone currently has a resolution of 163 pixels per inch. So 72 points is 163 pixels, or about 2.2639 pixels per point. Just remember that every glyph varies in height and width, so this is a very rough estimate of size. Generally, the distance between baselines will be a bit larger than the font's point size so that lines of text don't crash into each other.

如果您需要精确测量(并且您可能需要),那么您需要使用字体度量信息实际测量字体字形.您可以通过使用 NSString 的 UIKit 附加项,它可以让您在屏幕上呈现时测量特定字符串的大小.

If you need exact measurements (and you probably do) then you'll need to actually measure the font glyphs using the font metric information. You can do this by using NSString's UIKit additions, which will let you measure the size of a particular string when rendered on screen.

这篇关于字体大小(以像素为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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