AdaptiveFonts
简介
简而言之,AdaptiveFonts 是一个使用即时自定义字体的字体库。AdaptiveFonts 负责以下工作:
- 从 Google Fonts 或自定义资源下载数字字体。
- 将自定义字体注册到系统中。
- 动态和无缝地加载和使用自定义字体。
示例
要运行示例项目,请克隆仓库,然后首先从 Example
目录运行 pod install
。
安装
CocoaPods
如有需要,请安装 CocoaPods。
$ gem install cocoapods
在您的 Podfile
中添加 AdaptiveFonts
。
use_frameworks!
pod 'AdaptiveFonts'
运行以下命令。
$ pod install
使用方法
首先,在应用代理中设置 Google API 密钥。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
AdaptiveFonts.shared.APIKey = "paste your key here"
}
现在您准备好使用 AdaptiveFonts,只需记住一个 API。
let font = Font(family: "ABeeZee", variant: .regular)
let fontSize = 27
AdaptiveFonts.shared.font(for: font, size: fontSize) { uifont in
// Do something with the `uifont`.
}
注意:不要忘记在所有使用 AdaptiveFonts 的文件中 导入 AdaptiveFonts
。