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?
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