FontConstants 1.0

FontConstants 1.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Aug 2017
SwiftSwift Version 3.1
SPMSupports SPM

Maintained by Brendan Lee.


Downloads

Total40
Week0
Month0

Installs

Apps5
powered by Segment

GitHub

Stars2
Watchers1
Forks0
Issues0
Contributors1
Pull Requests0

Code

Files76
LOCLines of Code 1,760


  • By
  • Brendan Lee

A library to provide compiler-checked accessors to UIFont, with OS availability safety checks.

Example

label.font = UIFont.futura.mediumItalic.font(size: 12.0)

Introduction

UIFont's string-based API for choosing fonts is notoriously prone to typos and mistakes. Unfortunately, these often result in crashes or incorrect styles that aren't located until much later in development. FontConstants provides enum declarations and accessors for all fonts bundle with iOS.

All fonts are marked with @available tags so that the Swift compiler can prevent you from using fonts not available on a version of iOS, watchOS, or tvOS that your app supports.

Installation

e.g. pod 'FontConstants/futura'

You can get the FontName needed for the font you want by looking in the podspec file. General rule for naming is: Font family name, lowercase first letter, remove spaces / hyphens.

Manual Installation

If you want all fonts: Copy the the FontStyles.swift file from inside the Fonts/All Fonts folder.

If you want specific fonts: Copy the appropriate FontStyles.swift file from the font's folder inside Fonts.

How To Use

FontConstants are easy to use! You can access the font you want using this format: UIFont.fontFamily.fontStyle.font(size: 12.0)

Example
label.font = UIFont.futura.mediumItalic.font(size: 12.0)

If the font you want isn't available on your target version of iOS, watchOS, or tvOS then you'll see this error from the Swift compiler:

Availability Warning

Maintenance

The goal of this project is to keep this repo maintained as new versions of iOS, watchOS, tvOS, and Swift are released. This project tracks the availability of fonts from iOS Fonts font repo. If something is missing (that isn't removed by us), please make an issue there.

Special Thanks

Special thanks to iOS Fonts for making their font availability database open source and available under the Apache 2.0 license. Check it out here, and give them a big thank-you!