FontKit is a Swift library that makes it easy to use custom fonts with SwiftUI, UIKit, and AppKit.
FontKit can be installed with the Swift Package Manager:
https://github.com/danielsaidi/FontKit.git
You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.
FontKit has a CustomFont
struct that can be used to define and load custom font resources from any bundle.
For instance, this is how FontKit defines the four OpenDyslexic fonts that are embedded in the .module
bundle:
public extension CustomFont {
/// A regular OpenDyslexic font variant.
static let openDyslexic = CustomFont(
name: "OpenDyslexic-Regular",
displayName: "OpenDyslexic Regular",
fileExtension: "otf",
bundle: .module
)
/// A bold OpenDyslexic font variant.
static let openDyslexicBold = CustomFont(
name: "OpenDyslexic-Bold",
displayName: "OpenDyslexic Bold",
fileExtension: "otf",
bundle: .module
)
/// A bold italic OpenDyslexic font variant.
static let openDyslexicBoldItalic = CustomFont(
name: "OpenDyslexic-Bold-Italic",
displayName: "OpenDyslexic Bold Italic",
fileExtension: "otf",
bundle: .module
)
/// An italic OpenDyslexic font variant.
static let openDyslexicItalic = CustomFont(
name: "OpenDyslexic-Italic",
displayName: "OpenDyslexic Italic",
fileExtension: "otf",
bundle: .module
)
}
You can use SwiftuI Font
extensions to create CustomFont
-based fonts, or the .font(size:)
builder to create fonts for UIKit and AppKit.
The online documentation has more information, articles, code examples, etc.
The Demo
folder has a demo app that lets you test the library and its various fonts.
Feel free to reach out if you have questions, or want to contribute in any way:
- Website: danielsaidi.com
- E-mail: [email protected]
- Bluesky: @[email protected]
- Mastodon: @[email protected]
FontKit is available under the MIT license. See the LICENSE file for more info.