如何将点转换为 XCode 字体大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27546836/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 06:22:56  来源:igfitidea点击:

How to convert points to the XCode font size

iosxcodefontsinterface-builderxcode6

提问by FrozenHeart

I have the Photoshop file contains iOS application's design and I need to get info about font sizes for all labels and other controls. The size in Photoshop is shown in points by default, so how can I convert this value to the XCode one? For example:

我有包含 iOS 应用程序设计的 Photoshop 文件,我需要获取有关所有标签和其他控件的字体大小的信息。默认情况下,Photoshop 中的大小以磅为单位显示,那么如何将此值转换为 XCode 值呢?例如:

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

Thanks in advance.

提前致谢。

回答by alexey.hippie

Based on @MichaelCrawford answer, if AdobePoint = 1/72 of inch then we could calculate transition formula to ApplePoints.

根据@MichaelCrawford 的回答,如果 Adob​​ePoint = 1/72 英寸,那么我们可以计算到 ApplePoints 的转换公式。

What we need to know is:

我们需要知道的是:

  • Photoshop file resolution (px/inch) - Res
  • Photoshop mockup size, i.e for what iPhone factor it's created like @2x, @3x - Factor
  • Photoshop text size in AdobePoints - PSFont
  • Photoshop 文件分辨率(像素/英寸)- Res
  • Photoshop 模型大小,即它创建的 iPhone 因素,如 @2x、@3x - Factor
  • AdobePoints 中的 Photoshop 文本大小 - PSFont

Then, as I understand, you can calculate iPhone Font size (that actually equals iPhone points), like this

然后,据我所知,您可以像这样计算 iPhone 字体大小(实际上等于 iPhone 点数)

iPhoneFontSize = (Res / 72 ) * PSFont / Factor

iPhoneFontSize = (Res / 72) * PSFont / Factor

Example: You have mockup for iPhone 5, but all media also good for iPhone6+, then mockup size is iPhone 5 size * 3 = 960x1704, resolution is 401 (for iPhone6+). TabBar title font size on this mockup is 5 pt

示例:您有 iPhone 5 的样机,但所有媒体也适用于 iPhone6+,然后样机尺寸为 iPhone 5 尺寸 * 3 = 960x1704,分辨率为 401(适用于 iPhone6+)。此模型上的 TabBar 标题字体大小为 5 pt

Therefore, on iPhone you should setup size as 401 / 72 * 5 / 3 = 9.28

因此,在 iPhone 上你应该设置大小为 401 / 72 * 5 / 3 = 9.28

If resolution of file is 72 (for Web), you just need to divide PSFontSize to factor as you usually do to calculate control or imageView size.

如果文件的分辨率为 72(对于 Web),您只需要将 PSFontSize 划分为因子,就像通常计算控件或 imageView 大小一样。

回答by Mike Crawford

An "Adobe Point" is 1/72 of an inch, so 0.01389 inches.

“Adobe Point”是 1/72 英寸,所以是 0.01389 英寸。

The iPhone 6 screen has 376 by 667 "Apple Points" on a display whose diagonal is 4.7 inches. Now if I can remember my algebra... it's been so long.

iPhone 6 屏幕在对角线为 4.7 英寸的显示屏上有 376 x 667 个“Apple Points”。现在,如果我能记住我的代数……已经很久了。

376^2 + 667^2 = d^2

376^2 + 667^2 = d^2

where "d" is the count of Apple Points along the diagonal. d^2 is 579,578; d is the square root of that or 761.3. Divide that by 4.7 inches, we get 161.98 Apple Points per inch.

其中“d”是沿对角线的 Apple Points 数。d^2 是 579,578;d 是其平方根或 761.3。除以 4.7 英寸,我们得到每英寸 161.98 点 Apple Points。

So an Apple Point is somewhat less than half the height of an Adobe Point.

因此,Apple Point 的高度略小于 Adob​​e Point 的一半。

Does a factor of 0.444 work for you? Or perhaps the inverse of 2.25. Say your Photoshop image has 14-point type. In Xcode, you'd want 31 Points.

0.444 的系数对您有用吗?或者也许是 2.25 的倒数。假设您的 Photoshop 图像具有 14 磅字体。在 Xcode 中,您需要 31 点。

回答by Mike Crawford

Try creating a very simple app that has wide selection of different text sizes, all of them with Xcode points - what I called "Apple Points". So you could have Helvetica 6, Helvetica 7, Helvetica 8, all the way up to a size that's clearly larger than you will need for this design.

尝试创建一个非常简单的应用程序,它具有多种不同文本大小的选择,所有这些都带有 Xcode 点 - 我称之为“Apple Points”。因此,您可以使用 Helvetica 6、Helvetica 7、Helvetica 8,一直到明显大于此设计所需的尺寸。

Then print your Photoshop file on paper. Note that you can't really count on screen pixels to be any particular size. A hirez monitor with a small screen will also have smaller pixels.

然后在纸上打印您的 Photoshop 文件。请注意,您不能真正指望屏幕像素为任何特定大小。小屏幕的 hilez 显示器的像素也更小。

Compare the paper Photoshop design hardcopy to the text on the screen. That should give you an idea of the ratio.

将纸质 Photoshop 设计硬拷贝与屏幕上的文本进行比较。这应该让您对比率有所了解。