现今UI设计师都是按照PingFangSC字体来设计效果,每次写都是长长的一段代码,如下:
UIFont *font = [UIFont fontWithName:@"PingFangSC-Regular" size:16.0];
UIFont *font = [UIFont fontWithName:@"PingFangSC-Medium" size:16];
尤其是中间的字符串,特别容易写错,Xcode还没有提示。
so,为了防止写错,就写了一个分类来解决这个问题。
typedef NS_ENUM(NSUInteger, CMJPingFangSCType) {CMJPingFangSCTypeThin,CMJPingFangSCTypeUltralight,CMJPingFangSCTypeLight,CMJPingFangSCTypeRegular,CMJPingFangSCTypeMedium,CMJPingFangSCTypeSemibold,
};@interface UIFont (CMJFont)
+ (UIFont *)cmj_PingFangSCFontWithType:(CMJPingFangSCType)type fontSize:(CGFloat)size;
@end@implementation UIFont (CMJFont)
+ (UIFont *)cmj_PingFangSCFontWithType:(CMJPingFangSCType)type fontSize:(CGFloat)size
{UIFont *font = nil;switch (type) {case CMJPingFangSCTypeThin:font = [UIFont fontWithName:@"PingFangSC-Thin" size:size];break;case CMJPingFangSCTypeUltralight:font = [UIFont fontWithName:@"PingFangSC-Ultralight" size:size];break;case CMJPingFangSCTypeLight:font = [UIFont fontWithName:@"PingFangSC-Light" size:size];break;case CMJPingFangSCTypeRegular:font = [UIFont fontWithName:@"PingFangSC-Regular" size:size];break;case CMJPingFangSCTypeMedium:font = [UIFont fontWithName:@"PingFangSC-Medium" size:size];break;case CMJPingFangSCTypeSemibold:font = [UIFont fontWithName:@"PingFangSC-Semibold" size:size];break;default:break;}return font;
}@end
好久好久之后,直到有一天,和UI设计师聊天,说,
“苹果默认的字体不就是苹方字体吗?”
“What?”
咱也不知道,咱也不敢问,怎么办,回去打印一下:
<UICTFont: 0x14dd21b90> font-family: ".SFUI-Regular"; font-weight: normal; font-style: normal; font-size: 16.00pt
<UICTFont: 0x14de58bb0> font-family: "PingFangSC-Regular"; font-weight: normal; font-style: normal; font-size: 16.00pt
系统默认字体的font-family是".SFUI-Regular"(.SF是San Francisco的简写),苹方字体的font-family是"PingFangSC-Regular"。这样明显的证据摆在面前,为啥设计师说默认系统字体就是苹方字体呢?
“怎么说呢,手机一个字体包括中文和英文,对不?就问题来说:San Francisco是苹方字体的英文部分,中文部分叫苹方黑体。”
补充
San Francisco是苹方字体的英文部分,中文部分叫苹方黑体。但是,两者之间是有差距的。比如对数字的显示,平方字体显示的数字与前后汉字更加紧凑,但是San Francisco与前后汉字之间会有一定间隔。
附录:
UIFont *font1 = [UIFont systemFontOfSize:16];UIFont *font2 = [UIFont boldSystemFontOfSize:16];UIFont *font3 = [UIFont italicSystemFontOfSize:16];UIFont *font4 = [UIFont systemFontOfSize:16 weight:UIFontWeightRegular];UIFont *font5 = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];UIFont *font6 = [UIFont systemFontOfSize:16 weight:UIFontWeightSemibold];打印:
<UICTFont: 0x10a91cbe0> font-family: ".SFUI-Regular"; font-weight: normal; font-style: normal; font-size: 16.00pt
<UICTFont: 0x10a930de0> font-family: ".SFUI-Semibold"; font-weight: bold; font-style: normal; font-size: 16.00pt
<UICTFont: 0x10a92f650> font-family: ".SFUI-RegularItalic"; font-weight: normal; font-style: italic; font-size: 16.00pt<UICTFont: 0x105a01f80> font-family: ".SFUI-Regular"; font-weight: normal; font-style: normal; font-size: 16.00pt
<UICTFont: 0x105943960> font-family: ".SFUI-Medium"; font-weight: normal; font-style: normal; font-size: 16.00pt
<UICTFont: 0x1059443c0> font-family: ".SFUI-Semibold"; font-weight: bold; font-style: normal; font-size: 16.00pt