import TFontManager
class AppDelegate: NSObject, UIApplicationDelegate , UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
TFontManager.shared.setFontMappings([
fontsFamiliy[0] : [
.regular: SharedRes.fonts().montserrat_regular.fontName,
.medium: SharedRes.fonts().montserrat_medium.fontName,
.bold: SharedRes.fonts().montserrat_bold.fontName
],
fontsFamiliy[1]: [
.medium: SharedRes.fonts().inter_medium.fontName
],
fontsFamiliy[2]: [
.regular: SharedRes.fonts().tiny5_regular.fontName
]
])
```
return true
}
}
let fontsFamiliy: [String] = [
"montserrat",
"inter",
"tiny5"
]
struct ContentView: View {
var body: some View {
if let regularFont = TFontManager.shared.customFont(family: fontsFamiliy[2], size: 16, weight: .regular) {
Text("greet").font(regularFont)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
TFontManager 通过 CocoaPods 可用。安装它,只需将以下行添加到 Podfile
pod 'TFontManager'
Michelle Raouf, [email protected]
TFontManager 按MIT许可证可用。有关更多信息,请参阅 LICENSE 文件。