封装KBFont,适配字体
This commit is contained in:
@@ -33,6 +33,9 @@
|
||||
#define KB_BASE_URL @"http://192.168.1.144:7529/api"
|
||||
#endif
|
||||
|
||||
#import "KBFont.h"
|
||||
|
||||
|
||||
// Universal Links 通用链接
|
||||
#ifndef KB_UL_BASE
|
||||
#define KB_UL_BASE @"https://app.tknb.net/ul"
|
||||
|
||||
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 */
|
||||
|
||||
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
|
||||
|
||||
@@ -92,6 +92,7 @@
|
||||
|
||||
// Mine
|
||||
"Settings" = "Settings";
|
||||
"Personal" = "Personal";
|
||||
"My Keyboard" = "My Keyboard";
|
||||
"Notice" = "Notice";
|
||||
"Share App" = "Share App";
|
||||
@@ -159,6 +160,8 @@
|
||||
"Payment failed" = "Payment failed";
|
||||
"Purchase: %@ Coins %@" = "Purchase: %@ Coins %@";
|
||||
"Pay clicked" = "Pay clicked";
|
||||
"Points Recharge" = "Points Recharge";
|
||||
"My Points" = "My Points";
|
||||
|
||||
// Example categories/items
|
||||
"能力" = "Ability";
|
||||
|
||||
@@ -89,10 +89,11 @@
|
||||
"Rank" = "排行";
|
||||
"Recharge Now" = "立即充值";
|
||||
"By clicking Pay, you indicate your agreement to the" = "点击“支付”即表示您同意";
|
||||
"《Embership Agreement》" = "会员协议";
|
||||
"《Embership Agreement》" = "《会员协议》";
|
||||
|
||||
// Mine
|
||||
"Settings" = "设置";
|
||||
"Personal" = "个人";
|
||||
"My Keyboard" = "我的键盘";
|
||||
"Notice" = "通知";
|
||||
"Share App" = "分享app";
|
||||
@@ -156,7 +157,9 @@
|
||||
"Payment successful" = "支付成功";
|
||||
"Payment failed" = "支付失败";
|
||||
"Purchase: %@ Coins %@" = "购买:%@ Coins %@";
|
||||
"Pay clicked" = "Pay clicked";
|
||||
"Pay clicked" = "点击支付";
|
||||
"Points Recharge" = "积分充值";
|
||||
"My Points" = "我的积分";
|
||||
|
||||
// 示例商品/分类
|
||||
"能力" = "能力";
|
||||
|
||||
Reference in New Issue
Block a user