Skip to content

danielsaidi/FontKit

Repository files navigation

Project Icon

Version Swift 6.0 Documentation MIT License Sponsor my work

FontKit

FontKit is a Swift library that makes it easy to use custom fonts with SwiftUI, UIKit, and AppKit.

FontKit Preview

Installation

FontKit can be installed with the Swift Package Manager:

https://github.com/danielsaidi/FontKit.git

Support My Work

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.

Getting Started

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.

Documentation

The online documentation has more information, articles, code examples, etc.

Demo Application

The Demo folder has a demo app that lets you test the library and its various fonts.

Contact

Feel free to reach out if you have questions, or want to contribute in any way:

License

FontKit is available under the MIT license. See the LICENSE file for more info.

About

Easily handle custom fonts in SwiftUI, UIKit, and AppKit.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project