OGeek|极客世界-中国程序员成长平台

标题: ios - 在旧金山使用 fontWithSize API [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:35
标题: ios - 在旧金山使用 fontWithSize API

iOS 9 中的新 San Francisco 字体通过调整跟踪以及在 SF Display 和 SF Text 之间动态切换,针对将要使用的大小进行了优化。在 WWDC session #804 中指出,开发人员不应通过尝试使用 fontWithName 初始化 UIFont 来使用 San Francisco,例如:

UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [UIFont fontWithNameriginalFont.fontName size:44];

这是因为在使用 fontWithName API 时,系统无法针对新大小优化字体。

建议从原始字体中获取 UIFontDescriptor 并使用新字体创建新字体,如下所示:

UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [UIFont fontWithDescriptorriginalFont.fontDescriptor size:44];

但是,他们没有提及以下是否允许优化:

UIFont *originalFont = [UIFont systemFontOfSize:11];
UIFont *newFont = [originalFont fontWithSize:44];

我的问题是,fontWithSize API 的行为是否类似于 fontWithName API 或 fontWithDescriptor API - 它是否会产生优化的字体新尺寸还是没有?



Best Answer-推荐答案


我可以确认 fontWithSize 确实以新大小创建了优化的字体。

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

关于ios - 在旧金山使用 fontWithSize API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426341/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4