Using the fontWithSize API with San Francisco

二次信任 提交于 2019-12-08 03:08:09

问题


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];

This is because the system cannot optimize the font for the new size when using the fontWithName API.

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];

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?


回答1:


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


来源:https://stackoverflow.com/questions/32426341/using-the-fontwithsize-api-with-san-francisco

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!