其他分享
首页 > 其他分享> > OC Extension Font(字体宏定义)

OC Extension Font(字体宏定义)

作者:互联网

一直觉得自己写的不是技术,而是情怀,一个个的教程是自己这一路走来的痕迹。靠专业技能的成功是最具可复制性的,希望我的这条路能让你们少走弯路,希望我能帮你们抹去知识的蒙尘,希望我能帮你们理清知识的脉络,希望未来技术之巅上有你们也有我。

很多人在开发过程中会针对公司的需求都会对字体做一个宏定义的封装。方便日后的使用。下面简单的写一下。

在这里插入图片描述

#ifndef FontHeader_h
#define FontHeader_h

//kFont
#define kFont_10 [UIFont systemFontOfSize:10]
#define kFont_11 [UIFont systemFontOfSize:11]
#define kFont_12 [UIFont systemFontOfSize:12]
#define kFont_13 [UIFont systemFontOfSize:13]
#define kFont_14 [UIFont systemFontOfSize:14]
#define kFont_15 [UIFont systemFontOfSize:15]
#define kFont_16 [UIFont systemFontOfSize:16]
#define kFont_17 [UIFont systemFontOfSize:17]
#define kFont_18 [UIFont systemFontOfSize:18]
#define kFont_19 [UIFont systemFontOfSize:19]
#define kFont_20 [UIFont systemFontOfSize:20]

//PingFangSC-Medium 字体
#define kFont_PFSC_medium_x(x) [UIFont fontWithName:@"PingFangSC-Medium" size:x]
#define kFont_PFSC_medium_10 [UIFont fontWithName:@"PingFangSC-Medium" size:10]
#define kFont_PFSC_medium_11 [UIFont fontWithName:@"PingFangSC-Medium" size:11]
#define kFont_PFSC_medium_12 [UIFont fontWithName:@"PingFangSC-Medium" size:12]
#define kFont_PFSC_medium_13 [UIFont fontWithName:@"PingFangSC-Medium" size:13]
#define kFont_PFSC_medium_14 [UIFont fontWithName:@"PingFangSC-Medium" size:14]
#define kFont_PFSC_medium_15 [UIFont fontWithName:@"PingFangSC-Medium" size:15]
#define kFont_PFSC_medium_16 [UIFont fontWithName:@"PingFangSC-Medium" size:16]
#define kFont_PFSC_medium_17 [UIFont fontWithName:@"PingFangSC-Medium" size:17]
#define kFont_PFSC_medium_18 [UIFont fontWithName:@"PingFangSC-Medium" size:18]
#define kFont_PFSC_medium_19 [UIFont fontWithName:@"PingFangSC-Medium" size:19]
#define kFont_PFSC_medium_20 [UIFont fontWithName:@"PingFangSC-Medium" size:20]

#define kFont_PFSC_semibold_x(x) [UIFont fontWithName:@"PingFangSC-Semibold" size:x]
#define kFont_PFSC_semibold_10 [UIFont fontWithName:@"PingFangSC-Semibold" size:10]
#define kFont_PFSC_semibold_11 [UIFont fontWithName:@"PingFangSC-Semibold" size:11]
#define kFont_PFSC_semibold_12 [UIFont fontWithName:@"PingFangSC-Semibold" size:12]
#define kFont_PFSC_semibold_13 [UIFont fontWithName:@"PingFangSC-Semibold" size:13]
#define kFont_PFSC_semibold_14 [UIFont fontWithName:@"PingFangSC-Semibold" size:14]
#define kFont_PFSC_semibold_15 [UIFont fontWithName:@"PingFangSC-Semibold" size:15]
#define kFont_PFSC_semibold_16 [UIFont fontWithName:@"PingFangSC-Semibold" size:16]
#define kFont_PFSC_semibold_17 [UIFont fontWithName:@"PingFangSC-Semibold" size:17]
#define kFont_PFSC_semibold_18 [UIFont fontWithName:@"PingFangSC-Semibold" size:18]
#define kFont_PFSC_semibold_19 [UIFont fontWithName:@"PingFangSC-Semibold" size:19]
#define kFont_PFSC_semibold_20 [UIFont fontWithName:@"PingFangSC-Semibold" size:20]

#define kFont_PFSC_regular_x(x) [UIFont fontWithName:@"PingFangSC-Regular" size:x]
#define kFont_PFSC_regular_10 [UIFont fontWithName:@"PingFangSC-Regular" size:10]
#define kFont_PFSC_regular_11 [UIFont fontWithName:@"PingFangSC-Regular" size:11]
#define kFont_PFSC_regular_12 [UIFont fontWithName:@"PingFangSC-Regular" size:12]
#define kFont_PFSC_regular_13 [UIFont fontWithName:@"PingFangSC-Regular" size:13]
#define kFont_PFSC_regular_14 [UIFont fontWithName:@"PingFangSC-Regular" size:14]
#define kFont_PFSC_regular_15 [UIFont fontWithName:@"PingFangSC-Regular" size:15]
#define kFont_PFSC_regular_16 [UIFont fontWithName:@"PingFangSC-Regular" size:16]
#define kFont_PFSC_regular_17 [UIFont fontWithName:@"PingFangSC-Regular" size:17]
#define kFont_PFSC_regular_18 [UIFont fontWithName:@"PingFangSC-Regular" size:18]
#define kFont_PFSC_regular_19 [UIFont fontWithName:@"PingFangSC-Regular" size:19]
#define kFont_PFSC_regular_20 [UIFont fontWithName:@"PingFangSC-Regular" size:20]

#define kFont_PFSC_light_x(x) [UIFont fontWithName:@"PingFangSC-Light" size:x]
#define kFont_PFSC_light_10 [UIFont fontWithName:@"PingFangSC-Light" size:10]
#define kFont_PFSC_light_11 [UIFont fontWithName:@"PingFangSC-Light" size:11]
#define kFont_PFSC_light_12 [UIFont fontWithName:@"PingFangSC-Light" size:12]
#define kFont_PFSC_light_13 [UIFont fontWithName:@"PingFangSC-Light" size:13]
#define kFont_PFSC_light_14 [UIFont fontWithName:@"PingFangSC-Light" size:14]
#define kFont_PFSC_light_15 [UIFont fontWithName:@"PingFangSC-Light" size:15]
#define kFont_PFSC_light_16 [UIFont fontWithName:@"PingFangSC-Light" size:16]
#define kFont_PFSC_light_17 [UIFont fontWithName:@"PingFangSC-Light" size:17]
#define kFont_PFSC_light_18 [UIFont fontWithName:@"PingFangSC-Light" size:18]
#define kFont_PFSC_light_19 [UIFont fontWithName:@"PingFangSC-Light" size:19]
#define kFont_PFSC_light_20 [UIFont fontWithName:@"PingFangSC-Light" size:20]

// HelveticaNeue-CondensedBold
#define kFont_HN_CondensedBold_x(x) [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:x]
#define kFont_HN_CondensedBold_10 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:10]
#define kFont_HN_CondensedBold_11 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:11]
#define kFont_HN_CondensedBold_12 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:12]
#define kFont_HN_CondensedBold_13 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:13]
#define kFont_HN_CondensedBold_14 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:14]
#define kFont_HN_CondensedBold_15 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:15]
#define kFont_HN_CondensedBold_16 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:16]
#define kFont_HN_CondensedBold_17 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:17]
#define kFont_HN_CondensedBold_18 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:18]
#define kFont_HN_CondensedBold_19 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:19]
#define kFont_HN_CondensedBold_20 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:20]
#define kFont_HN_CondensedBold_24 [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:24]

/**< 加粗号字体> */
#define kFont_10_weight_x(x) [UIFont systemFontOfSize:10 weight:x]
#define kFont_11_weight_x(x) [UIFont systemFontOfSize:11 weight:x]
#define kFont_12_weight_x(x) [UIFont systemFontOfSize:12 weight:x]
#define kFont_13_weight_x(x) [UIFont systemFontOfSize:13 weight:x]
#define kFont_14_weight_x(x) [UIFont systemFontOfSize:14 weight:x]
#define kFont_15_weight_x(x) [UIFont systemFontOfSize:15 weight:x]
#define kFont_16_weight_x(x) [UIFont systemFontOfSize:16 weight:x]
#define kFont_17_weight_x(x) [UIFont systemFontOfSize:17 weight:x]
#define kFont_18_weight_x(x) [UIFont systemFontOfSize:18 weight:x]
#define kFont_19_weight_x(x) [UIFont systemFontOfSize:19 weight:x]
#define kFont_20_weight_x(x) [UIFont systemFontOfSize:20 weight:x]

#define kFont_COPPERPLATE_LIGHT_20 [UIFont fontWithName:@"COPPERPLATE-LIGHT" size:20]
#define kFont_COPPERPLATE_20 [UIFont fontWithName:@"COPPERPLATE" size:20]

#define kFont_IOS_Italic_20 [UIFont fontWithName:@"IowanOldStyle-Italic" size:20]
#define kFont_IOS_Roman_20 [UIFont fontWithName:@"IowanOldStyle-Roman" size:20]
#define kFont_IOS_BoldItalic_20 [UIFont fontWithName:@"IowanOldStyle-BoldItalic" size:20]
#define kFont_IOS_Bold_20 [UIFont fontWithName:@"IowanOldStyle-Bold" size:20]

#define kFont_KT_Regular_20 [UIFont fontWithName:@"KohinoorTelugu-Regular" size:20]
#define kFont_KT_Medium_20 [UIFont fontWithName:@"KohinoorTelugu-Medium" size:20]
#define kFont_KT_Light_20 [UIFont fontWithName:@"KohinoorTelugu-Light" size:20]

#define kFont_T_20 [UIFont fontWithName:@"Thonburi" size:20]
#define kFont_T_Bold_20 [UIFont fontWithName:@"Thonburi-Bold" size:20]
#define kFont_T_Light_20 [UIFont fontWithName:@"Thonburi-Light" size:20]

#define kFont_CNPS_BoldMT_20 [UIFont fontWithName:@"CourierNewPS-BoldMT" size:20]
#define kFont_CNPS_ItalicMT_20 [UIFont fontWithName:@"CourierNewPS-ItalicMT" size:20]
#define kFont_CNPSMT_20 [UIFont fontWithName:@"CourierNewPSMT" size:20]

#define kFont_GS_Italic_20 [UIFont fontWithName:@"GillSans-Italic" size:20]

#define kIs375OrMax (kSCREEN_WIDTH < 375)
#define kFont_auto_reg_12 (kIs375OrMax ? ([UIFont fontWithName:@"PingFangSC-Regular" size:11]) : ([UIFont fontWithName:@"PingFangSC-Regular" size:12]))
#define kFont_auto_reg_13 (kIs375OrMax ? ([UIFont fontWithName:@"PingFangSC-Regular" size:12]) : ([UIFont fontWithName:@"PingFangSC-Regular" size:13]))

#endif /* FontHeader_h */

字体效果

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

标签:size,fontWithName,Extension,UIFont,OC,kFont,Font,PingFangSC,define
来源: https://blog.csdn.net/weixin_38716347/article/details/119903091