封装KBFont,适配字体
This commit is contained in:
53
Shared/KBFont.m
Normal file
53
Shared/KBFont.m
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// KBFont.m
|
||||
//
|
||||
|
||||
#import "KBFont.h"
|
||||
|
||||
#if __OBJC__
|
||||
|
||||
@implementation KBFont
|
||||
|
||||
+ (UIFont *)fontOfSize:(CGFloat)designSize weight:(UIFontWeight)weight {
|
||||
// 以 375 设计稿为基准等比缩放(见 KBConfig.h 中的 KBFit)
|
||||
CGFloat scaledSize = KBFit(designSize);
|
||||
return [UIFont systemFontOfSize:scaledSize weight:weight];
|
||||
}
|
||||
|
||||
+ (UIFont *)regular:(CGFloat)designSize {
|
||||
return [self fontOfSize:designSize weight:UIFontWeightRegular];
|
||||
}
|
||||
|
||||
+ (UIFont *)medium:(CGFloat)designSize {
|
||||
return [self fontOfSize:designSize weight:UIFontWeightMedium];
|
||||
}
|
||||
|
||||
+ (UIFont *)semibold:(CGFloat)designSize {
|
||||
return [self fontOfSize:designSize weight:UIFontWeightSemibold];
|
||||
}
|
||||
|
||||
+ (UIFont *)bold:(CGFloat)designSize {
|
||||
return [self fontOfSize:designSize weight:UIFontWeightBold];
|
||||
}
|
||||
|
||||
#pragma mark - 语义字体(可按设计自由修改数值)
|
||||
|
||||
+ (UIFont *)titleFont {
|
||||
// 例如:18pt,半粗体
|
||||
return [self fontOfSize:18.0 weight:UIFontWeightSemibold];
|
||||
}
|
||||
|
||||
+ (UIFont *)bodyFont {
|
||||
// 例如:14pt,常规
|
||||
return [self regular:14.0];
|
||||
}
|
||||
|
||||
+ (UIFont *)captionFont {
|
||||
// 例如:12pt,常规
|
||||
return [self regular:12.0];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user