Giter VIP home page Giter VIP logo

fontkit's Introduction

FontKit for SwiftUI and UIKit

FontKit is a Swift utility designed to bridge the gap between SwiftUI and UIKit font management in iOS development. This tool provides a unified approach to handling font styling, including dynamic type and font designs like rounded, serif, and monospaced, focusing on the SF Pro system font. It ensures accessibility, consistency, and ease of use in typography across your entire app.

Features

  • Unified Font Management: Manage fonts in SwiftUI and UIKit with a single, versatile utility class. It is specifically optimized for the SF Pro system font.
  • Dynamic Type Support: Fully supports Dynamic Type, allowing font sizes to adjust automatically based on the user's accessibility settings.
  • Multiple Font Designs: Offers the ability to use various font designs, including .rounded, .serif, and .monospaced, enhancing the visual appeal of your app, especially with the SF Pro font family.
  • Customizable Font Weights: Provides flexibility in choosing font weights, from .ultraLight to .black, to match different design needs.
  • Ease of Use: Simplifies the font selection and usage process in both SwiftUI and UIKit environments.

Usage

SwiftUI Example

Text("Hello, SwiftUI!")
    .font(FontKit.font(forTextStyle: .body, weight: .semibold, design: .rounded))

UIKit Example

let label = UILabel()
label.font = FontKit.font(forTextStyle: .body, weight: .semibold, design: .rounded)

Implementation Details

FontKit includes a set of methods and mappings that facilitate the use of fonts in both SwiftUI and UIKit. It abstracts away the complexities of handling different font types, text styles, and designs, providing a straightforward and consistent API.

  • font(forTextStyle:weight:design:): The primary method to retrieve fonts, accepting parameters for text style, weight, and design.
  • TextStyle: A custom enum mapping to SwiftUI's and UIKit's text styles.
  • uiFontWeight(from:) and uiFontDesign(from:): Helper methods for mapping SwiftUI types to their UIKit equivalents.

Requirements

  • iOS 13.0 or later for the full range of design features.
  • Swift 5.1 or later.
  • Xcode 11 or later.

Extended Usage Examples for FontKit

SwiftUI Examples:

  1. Large Title with Heavy Weight in Rounded Style:

    Text("Large Title")
        .font(FontKit.font(forTextStyle: .largeTitle, weight: .heavy, design: .rounded))
  2. Body Text in Monospaced Design:

    Text("Body Text")
        .font(FontKit.font(forTextStyle: .body, weight: .regular, design: .monospaced))
  3. Caption Text in Serif Design:

    Text("Caption Text")
        .font(FontKit.font(forTextStyle: .caption, weight: .light, design: .serif))

UIKit Examples:

  1. Title Label with Semibold Weight in Rounded Style:

    let titleLabel = UILabel()
    titleLabel.font = FontKit.font(forTextStyle: .title1, weight: .semibold, design: .rounded)
    titleLabel.text = "Title Label"
  2. Subheadline Label in Monospaced Design:

    let subheadlineLabel = UILabel()
    subheadlineLabel.font = FontKit.font(forTextStyle: .subheadline, weight: .medium, design: .monospaced)
    subheadlineLabel.text = "Subheadline Label"
  3. Footnote Label in Default System Design:

    let footnoteLabel = UILabel()
    footnoteLabel.font = FontKit.font(forTextStyle: .footnote, weight: .regular)
    footnoteLabel.text = "Footnote Label"

Supported Font Weights

  1. UltraLight: .ultraLight
  2. Thin: .thin
  3. Light: .light
  4. Regular: .regular
  5. Medium: .medium
  6. Semibold: .semibold
  7. Bold: .bold
  8. Heavy: .heavy
  9. Black: .black

Supported Text Styles:

  1. Large Title: .largeTitle
  2. Title: .title
  3. Title2: .title2
  4. Title3: .title3
  5. Headline: .headline
  6. Subheadline: .subheadline
  7. Body: .body
  8. Callout: .callout
  9. Footnote: .footnote
  10. Caption: .caption
  11. Caption2: .caption2

Supported Font Designs

Designs applicable for iOS 13.0 and later:

  1. Default: .default
  2. Rounded: .rounded
  3. Serif: .serif
  4. Monospaced: .monospaced

fontkit's People

Contributors

bartolli avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.