FontKit

FontKit

一种在 iOS、iPadOS、MacOS、WatchOS、TvOS 应用程序中使用自定义字体的新方法。

特性

可用字体

我们将不断向此软件包添加更多字体

📦 安装

Swift Package Manager

Swift Package Manager 是一种自动分发 Swift 代码的工具,并已集成到 swift 编译器中。

在 Xcode 中使用其 Github 仓库 URL 添加此 Swift 包。(File > Swift Packages > Add Package Dependency...)

添加此 URL https://github.com/VishwaiOSDev/FontKit.git 并选择 Add Package

添加后,选择 FontKit 以及您希望添加到应用程序中的字体。 您可以使用多种字体。

Choose Package for FontKit

注意: 必须选择 FontKit

🚀 如何使用

FontKit 让您的生活更轻松。

首先,在 SwiftUI App 的根目录导入 FontKit 和选择的字体 *(FontInter, FontLato)*。

import FontKit
import FontInter

在 init 中注册字体。

import FontKit
import FontInter

@main
struct FontKit_TestApp: App {
    
    init() {
        FontKit.registerInter()
        // You can register multiple fonts in here
        // FontKit.registerLato()
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

借助修饰符,我们可以轻松使用 FontKit。

Text("Hello, world!")
    .font(.inter(.bold(size: 22)))

注意: 使用此修饰符时,请确保已导入 FontKit。

字体家族和字体类型

字体名称 字体家族 注册函数
Inter .font(.inter) registerInter()
Lato .font(.lato) registerLato()
OpenSans .font(.openSans) registerOpenSans()
Roboto .font(.roboto) registerRoboto()
Poppins .font(.poppins) registerPoppins()
Raleway .font(.raleway) registerRaleway()
Ubuntu .font(.ubuntu) registerUbuntu()
Rubik .font(.rubik) registerRubik()
Menlo .font(.menlo) registerMenlo()

字体类型

您可以将这些字体类型用于自定义字体。

示例

以下是 FontKit 的用法示例

Text("Hello, Inter!")
    .font(.inter(.bold(size: 22)))
Text("Hello, Lato!")
    .font(.lato(.heavy(size: 18)))
Text("Hello, Poppins!")
    .font(.poppins(.semibold(size: 20)))
Text("Hello, OpenSans!")
    .font(.openSans(.regular(size: 13)))
Text("Hello, Roboto!")
    .font(.roboto(.thin(size: 16)))

许可证

FontKit 在 MIT 许可证下发布。

MIT License

Copyright (c) 2022 VishwaiOSDev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.