Latest 1.0
Homepage https://github.com/52inc/FontConstants
License MIT
Platforms ios 8.0, tvos 9.0, watchos 2.0, requires ARC
Frameworks UIKit
Authors

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

Installation with Cocoapods

If you want all fonts in iOS imported:

pod 'FontConstants'

If you only want a specific font imported (you can do multiple with this method):

pod 'FontConstants/FontName'

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!

Latest podspec

{
    "name": "FontConstants",
    "version": "1.0",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0",
        "watchos": "2.0"
    },
    "license": "MIT",
    "summary": "The safest way to use UIFont",
    "homepage": "https://github.com/52inc/FontConstants",
    "authors": {
        "Brendan Lee": "[email protected]"
    },
    "source": {
        "git": "https://github.com/52inc/FontConstants.git",
        "tag": "1.0"
    },
    "description": "FontConstants provides compiler-checked enums for safe and easy use of UIFont. With enums and OS version availability checks, FontConstants helps make sure UIFont works like you expect.",
    "requires_arc": true,
    "frameworks": "UIKit",
    "default_subspecs": "AllFonts",
    "pushed_with_swift_version": "3.1",
    "subspecs": [
        {
            "name": "academyEngravedLET",
            "source_files": "Fonts/Academy Engraved LET/*.{swift}"
        },
        {
            "name": "alNile",
            "source_files": "Fonts/Al Nile/*.{swift}"
        },
        {
            "name": "americanTypewriter",
            "source_files": "Fonts/American Typewriter/*.{swift}"
        },
        {
            "name": "appleColorEmoji",
            "source_files": "Fonts/Apple Color Emoji/*.{swift}"
        },
        {
            "name": "appleSDGothicNeo",
            "source_files": "Fonts/Apple SD Gothic Neo/*.{swift}"
        },
        {
            "name": "arial",
            "source_files": "Fonts/Arial/*.{swift}"
        },
        {
            "name": "arialHebrew",
            "source_files": "Fonts/Arial Hebrew/*.{swift}"
        },
        {
            "name": "arialRoundedMTBold",
            "source_files": "Fonts/Arial Rounded MT Bold/*.{swift}"
        },
        {
            "name": "avenir",
            "source_files": "Fonts/Avenir/*.{swift}"
        },
        {
            "name": "avenirNext",
            "source_files": "Fonts/Avenir Next/*.{swift}"
        },
        {
            "name": "avenirNextCondensed",
            "source_files": "Fonts/Avenir Next Condensed/*.{swift}"
        },
        {
            "name": "banglaSangamMN",
            "source_files": "Fonts/Bangla Sangam MN/*.{swift}"
        },
        {
            "name": "baskerville",
            "source_files": "Fonts/Baskerville/*.{swift}"
        },
        {
            "name": "bodoniOrnaments",
            "source_files": "Fonts/Bodoni Ornaments/*.{swift}"
        },
        {
            "name": "bodoni72",
            "source_files": "Fonts/Bodoni 72/*.{swift}"
        },
        {
            "name": "bodoni72Oldstyle",
            "source_files": "Fonts/Bodoni 72 Oldstyle/*.{swift}"
        },
        {
            "name": "bodoni72Smallcaps",
            "source_files": "Fonts/Bodoni 72 Smallcaps/*.{swift}"
        },
        {
            "name": "bradleyHand",
            "source_files": "Fonts/Bradley Hand/*.{swift}"
        },
        {
            "name": "chalkboardSE",
            "source_files": "Fonts/Chalkboard SE/*.{swift}"
        },
        {
            "name": "chalkduster",
            "source_files": "Fonts/Chalkduster/*.{swift}"
        },
        {
            "name": "cochin",
            "source_files": "Fonts/Cochin/*.{swift}"
        },
        {
            "name": "copperplate",
            "source_files": "Fonts/Copperplate/*.{swift}"
        },
        {
            "name": "courier",
            "source_files": "Fonts/Courier/*.{swift}"
        },
        {
            "name": "courierNew",
            "source_files": "Fonts/Courier New/*.{swift}"
        },
        {
            "name": "dBLCDTemp",
            "source_files": "Fonts/DB LCD Temp/*.{swift}"
        },
        {
            "name": "dINAlternate",
            "source_files": "Fonts/DIN Alternate/*.{swift}"
        },
        {
            "name": "dINCondensed",
            "source_files": "Fonts/DIN Condensed/*.{swift}"
        },
        {
            "name": "damascus",
            "source_files": "Fonts/Damascus/*.{swift}"
        },
        {
            "name": "devanagariSangamMN",
            "source_files": "Fonts/Devanagari Sangam MN/*.{swift}"
        },
        {
            "name": "didot",
            "source_files": "Fonts/Didot/*.{swift}"
        },
        {
            "name": "diwanMishafi",
            "source_files": "Fonts/Diwan Mishafi/*.{swift}"
        },
        {
            "name": "euphemiaUCAS",
            "source_files": "Fonts/Euphemia UCAS/*.{swift}"
        },
        {
            "name": "farah",
            "source_files": "Fonts/Farah/*.{swift}"
        },
        {
            "name": "futura",
            "source_files": "Fonts/Futura/*.{swift}"
        },
        {
            "name": "geezaPro",
            "source_files": "Fonts/Geeza Pro/*.{swift}"
        },
        {
            "name": "georgia",
            "source_files": "Fonts/Georgia/*.{swift}"
        },
        {
            "name": "gillSans",
            "source_files": "Fonts/Gill Sans/*.{swift}"
        },
        {
            "name": "gujaratiSangamMN",
            "source_files": "Fonts/Gujarati Sangam MN/*.{swift}"
        },
        {
            "name": "gurmukhiMN",
            "source_files": "Fonts/Gurmukhi MN/*.{swift}"
        },
        {
            "name": "heitiSC",
            "source_files": "Fonts/Heiti SC/*.{swift}"
        },
        {
            "name": "heitiTC",
            "source_files": "Fonts/Heiti TC/*.{swift}"
        },
        {
            "name": "helvetica",
            "source_files": "Fonts/Helvetica/*.{swift}"
        },
        {
            "name": "helveticaNeue",
            "source_files": "Fonts/Helvetica Neue/*.{swift}"
        },
        {
            "name": "hiraginoKakuGothicProN",
            "source_files": "Fonts/Hiragino Kaku Gothic ProN/*.{swift}"
        },
        {
            "name": "hiraginoMinchoProN",
            "source_files": "Fonts/Hiragino Mincho ProN/*.{swift}"
        },
        {
            "name": "hoeflerText",
            "source_files": "Fonts/Hoefler Text/*.{swift}"
        },
        {
            "name": "iowanOldStyle",
            "source_files": "Fonts/Iowan Old Style/*.{swift}"
        },
        {
            "name": "kailasa",
            "source_files": "Fonts/Kailasa/*.{swift}"
        },
        {
            "name": "kannadaSangamMN",
            "source_files": "Fonts/Kannada Sangam MN/*.{swift}"
        },
        {
            "name": "khmerSangamMN",
            "source_files": "Fonts/KhmerSangamMN/*.{swift}"
        },
        {
            "name": "kohinoorDevanagari",
            "source_files": "Fonts/KohinoorDevanagari/*.{swift}"
        },
        {
            "name": "laoSangamMN",
            "source_files": "Fonts/LaoSangamMN/*.{swift}"
        },
        {
            "name": "malayalamSangamMN",
            "source_files": "Fonts/Malayalam Sangam MN/*.{swift}"
        },
        {
            "name": "marion",
            "source_files": "Fonts/Marion/*.{swift}"
        },
        {
            "name": "menlo",
            "source_files": "Fonts/Menlo/*.{swift}"
        },
        {
            "name": "markerFelt",
            "source_files": "Fonts/Marker Felt/*.{swift}"
        },
        {
            "name": "noteworthy",
            "source_files": "Fonts/Noteworthy/*.{swift}"
        },
        {
            "name": "optima",
            "source_files": "Fonts/Optima/*.{swift}"
        },
        {
            "name": "oriyaSangamMN",
            "source_files": "Fonts/Oriya Sangam MN/*.{swift}"
        },
        {
            "name": "palatino",
            "source_files": "Fonts/Palatino/*.{swift}"
        },
        {
            "name": "papyrus",
            "source_files": "Fonts/Papyrus/*.{swift}"
        },
        {
            "name": "partyLET",
            "source_files": "Fonts/Party LET/*.{swift}"
        },
        {
            "name": "savoyeLetPlain",
            "source_files": "Fonts/Savoye Let Plain/*.{swift}"
        },
        {
            "name": "sinhalaSangamMN",
            "source_files": "Fonts/Sinhala Sangam MN/*.{swift}"
        },
        {
            "name": "snellRoundhand",
            "source_files": "Fonts/Snell Roundhand/*.{swift}"
        },
        {
            "name": "superclarendon",
            "source_files": "Fonts/Superclarendon/*.{swift}"
        },
        {
            "name": "symbol",
            "source_files": "Fonts/Symbol/*.{swift}"
        },
        {
            "name": "tamilSangamMN",
            "source_files": "Fonts/Tamil Sangam MN/*.{swift}"
        },
        {
            "name": "teluguSangamMN",
            "source_files": "Fonts/Telugu Sangam MN/*.{swift}"
        },
        {
            "name": "thonburi",
            "source_files": "Fonts/Thonburi/*.{swift}"
        },
        {
            "name": "timesNewRoman",
            "source_files": "Fonts/Times New Roman/*.{swift}"
        },
        {
            "name": "trebuchetMS",
            "source_files": "Fonts/Trebuchet MS/*.{swift}"
        },
        {
            "name": "verdana",
            "source_files": "Fonts/Verdana/*.{swift}"
        },
        {
            "name": "zapfDingbats",
            "source_files": "Fonts/Zapf Dingbats/*.{swift}"
        },
        {
            "name": "zapfino",
            "source_files": "Fonts/Zapfino/*.{swift}"
        },
        {
            "name": "AllFonts",
            "source_files": "Fonts/All Fonts/*.{swift}"
        }
    ]
}

Pin It on Pinterest

Share This