首页 > 解决方案 > fontDescriptorWithSymbolicTraits 方法返回不同字体系列中的新字体描述符引用,而不是 iOS13 上的相同字体系列

问题描述

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

预期成绩:

粗体字体应属于同一字体系列,即 SFUI-Regular

实际结果:

粗体字体属于不同的字体系列,即 TimesNewRoman

标签: iosobjective-cxcode11ios13

解决方案


看起来苹果在属性字符串的字体上有一个错误,因为...iOS 13 beta!!!但这个问题仅在 Xcode 11+ 上显示。

打开雷达

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


推荐阅读