【问题标题】:Using the fontWithSize API with San Francisco在旧金山使用 fontWithSize API
【发布时间】:2015-12-02 06:45:47
【问题描述】:

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

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

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

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

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

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

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

我的问题是,fontWithSize API 的行为是否类似于 fontWithName API 或 fontWithDescriptor API - 是否会针对新大小优化字体?

【问题讨论】:

    标签: ios fonts ios9 uifont uifontdescriptor


    【解决方案1】:

    我可以确认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
    

    【讨论】:

      猜你喜欢
      • 2015-12-27
      • 1970-01-01
      • 2016-10-06
      • 2016-01-10
      • 2019-07-20
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多