说明
1.加粗斜体,字体样式,API无法同时设置斜体,加粗。
2.因此UI为字体样式,需导入字体库,导致增大包体积。
-
UIFontDescriptorSymbolicTraits
可有效解决此问题
UIFontDescriptorSymbolicTraits的组合使用
/// SF-Pro-Display-HeavyItalic 斜体加粗
/// @param fontSize 字号
/// @param bold 加粗
/// @param italic 斜体
/// @param weight 加粗量级
+ (UIFont *)SFDisplayFontWithSize:(CGFloat)fontSize
bold:(BOOL)bold itatic:(BOOL)italic weight:(UIFontWeight)weight {
UIFont *font = [UIFont systemFontOfSize:fontSize weight:weight];
UIFontDescriptorSymbolicTraits symbolicTraits = 0;
if (italic) {
symbolicTraits |= UIFontDescriptorTraitItalic;
}
if (bold) {
symbolicTraits |= UIFontDescriptorTraitBold;
}
UIFont *specialFont = [UIFont fontWithDescriptor:[[font fontDescriptor] fontDescriptorWithSymbolicTraits:symbolicTraits] size:font.pointSize];
return specialFont;
}