在旧金山使用fontWithSize API [英] Using the fontWithSize API with San Francisco
问题描述
通过调整跟踪并在SF Display和SF Text之间动态切换,iOS 9中新的San Francisco字体针对将要使用的大小进行了优化.在WWDC会话#804中指出,开发人员不应通过尝试使用fontWithName
初始化UIFont
来使用旧金山,例如:
The new San Francisco fonts in iOS 9 are optimized for the size it will be used at, by adjusting tracking and dynamically switching between SF Display and SF Text. It was noted in the WWDC session #804 developers should not use San Francisco by attempting to initialize a UIFont
using fontWithName
, for example:
UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [UIFont fontWithName:originalFont.fontName size:44];
这是因为使用fontWithName
API时系统无法针对新大小优化字体.
This is because the system cannot optimize the font for the new size when using the fontWithName
API.
相反,建议从原始字体中获取UIFontDescriptor
并从中以新大小创建新字体,如下所示:
Instead it was recommended to get the UIFontDescriptor
from the original font and create a new font from that at the new size, like so:
UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [UIFont fontWithDescriptor:originalFont.fontDescriptor size:44];
但是,他们没有提到以下内容是否允许优化:
However, they did not mention if the following allows for optimizations or not:
UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [originalFont fontWithSize:44];
我的问题是,fontWithSize
API的行为是否像fontWithName
API或fontWithDescriptor
API一样-是否导致针对新大小的优化字体?
My question is, does the fontWithSize
API behave like the fontWithName
API or the fontWithDescriptor
API - does it result in an optimized font for the new size or not?
推荐答案
我可以确认fontWithSize
确实以新大小创建了优化的字体.
I can confirm fontWithSize
does create an optimized font at the new size.
Printing description of originalFont:
<UICTFont: 0x7f8d9ba85340> font-family: ".SFUIText-Regular"; font-weight: normal; font-style: normal; font-size: 11.00pt
Printing description of newFont:
<UICTFont: 0x7f8d9ba7fe70> font-family: ".SFUIDisplay-Regular"; font-weight: normal; font-style: normal; font-size: 44.00pt
这篇关于在旧金山使用fontWithSize API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!