封装KBFont,适配字体
This commit is contained in:
45
Shared/KBFont.h
Normal file
45
Shared/KBFont.h
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// KBFont.h
|
||||
// 全局字体工具(主 App 与键盘扩展共用)
|
||||
//
|
||||
// 说明:
|
||||
// - 不做系统 Dynamic Type 适配,字号只按设计稿 + 屏幕宽度等比缩放
|
||||
// - 统一从这里取字体,避免在各处到处写死数字和 weight
|
||||
//
|
||||
|
||||
#ifndef KBFont_h
|
||||
#define KBFont_h
|
||||
|
||||
#if __OBJC__
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "KBConfig.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface KBFont : NSObject
|
||||
|
||||
/// 按设计稿字号 + 屏幕宽度缩放,返回系统字体
|
||||
/// 使用示例:label.font = [KBFont fontOfSize:14 weight:UIFontWeightRegular];
|
||||
+ (UIFont *)fontOfSize:(CGFloat)designSize weight:(UIFontWeight)weight;
|
||||
|
||||
/// 常用 weight 封装(设计稿字号)
|
||||
+ (UIFont *)regular:(CGFloat)designSize;
|
||||
+ (UIFont *)medium:(CGFloat)designSize;
|
||||
+ (UIFont *)semibold:(CGFloat)designSize;
|
||||
+ (UIFont *)bold:(CGFloat)designSize;
|
||||
|
||||
/// 根据当前项目大致预设的几个常用语义字号
|
||||
/// 可以按设计调整里面的数值,不影响调用方
|
||||
+ (UIFont *)titleFont; // 标题,例如 18pt 半粗
|
||||
+ (UIFont *)bodyFont; // 正文,例如 14pt 常规
|
||||
+ (UIFont *)captionFont; // 辅助/备注,例如 12pt 常规
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif /* __OBJC__ */
|
||||
|
||||
#endif /* KBFont_h */
|
||||
|
||||
Reference in New Issue
Block a user