【问题标题】:fontDescriptorWithSymbolicTraits method returns a new font descriptor reference in a different font family instead of same font family on iOS13fontDescriptorWithSymbolicTraits 方法返回不同字体系列中的新字体描述符引用,而不是 iOS13 上的相同字体系列
【发布时间】:2019-08-09 06:36:49
【问题描述】:

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

【问题讨论】:

  • 遇到了完全相同的问题,代码更简单:[UIFont fontWithName:[UIFont boldSystemFontOfSize:12.].fontName size:12.] 在 iOS 13 上返回 TimeNewRoman 字体而不是 San Francisco。这个用于工作的代码....从 iOS 3 开始!你知道发生了什么吗?
  • Apple 回应 > “这是由于系统字体名称使用不当造成的。与其按名称创建新的字体描述符,不如使用 - [UIFont fontDescriptor]”

标签: ios objective-c xcode11 ios13


【解决方案1】:

看起来 Apple 自...iOS 13 beta 以来就存在属性字符串字体的错误!但是这个问题只在 Xcode 11+ 上显示。

Open radar

最好的办法是不使用系统字体,直接使用字体名称。

【讨论】:

    猜你喜欢
    • 2018-10-03
    • 2018-06-14
    • 1970-01-01
    • 2014-03-03
    • 2014-05-05
    • 2012-06-16
    • 2014-01-29
    • 1970-01-01
    • 2014-01-29
    相关资源
    最近更新 更多