fontDescriptorWithSymbolicTraits方法在iOS13上以不同的字体系列而不是相同的字体系列返回新的字体描述符引用

har*_*823 6 objective-c ios ios13 xcode11

fontDescriptorWithSymbolicTraits方法在iOS13上以不同的字体系列而不是相同的字体系列返回新的字体描述符引用

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [ViewController bold];
}


+(UIFont *)systemFontCaption
{
    return [UIFont systemFontOfSize:20.0f weight:UIFontWeightRegular];
}

+(UIFont*)bold
{
    UIFont *font = [ViewController systemFontCaption];

    UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:font.fontName size:font.pointSize];
    UIFontDescriptor *styleDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:[fontDescriptor symbolicTraits] | UIFontDescriptorTraitBold];
    UIFont *boldFont = [UIFont fontWithDescriptor:styleDescriptor size:font.pointSize];
    return  boldFont;
}
Run Code Online (Sandbox Code Playgroud)

预期成绩:

粗体字体应为相同的字体系列,即SFUI-Regular

实际结果:

粗体字体属于不同的字体家族,即TimesNewRoman

Ale*_*tor 0

看起来 Apple 自 iOS 13 beta 以来就存在属性字符串字体的错误!但此问题仅在 Xcode 11+ 上出现。

开放式雷达

最好的解决方案是不使用系统字体,而是准确使用字体名称。