【发布时间】: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