Skip to content
This repository has been archived by the owner on Sep 17, 2022. It is now read-only.
/ Typesetter Public archive

A thin wrapper around dynamic type. Size your fonts across all accessibility sizes together with design

License

Notifications You must be signed in to change notification settings

ios-studio/Typesetter

Repository files navigation

Typesetter Build Status codecov.io Carthage compatible

Dynamic type is great, but to adjust the typographic setup to work with the font & content sizes available can be daunting. This library puts you back in control by reading the sizes from a CSV file which can easily be generated from Google Docs or other common table editors.

The goal is to empower you and your designer with the ability to cooperate via this CSV file and leverage the power of Dynamic Type.

Installation

Add the following your Cartfile:

For Swift 3:

github "ios-studio/Typesetter" ~> 1.0.0

For Swift 2.x:

github "ios-studio/Typesetter" ~> 0.1.3

Add the following your Podfile:

For Swift 3:

pod "Typesetter", "~> 1.0.0"

For Swift 2.x:

pod "Typesetter", "~> 0.1.3"

Default Setup

Typesetter will look for a file named FontSizes.csv in the specified bundle or at the specified path. The contents of the file should look like this. It is important to not delete any columns or rows, otherwise Typesetter will default to a standard font size for all the fonts.

For the fonts you'd like to use in your project, define a class which conforms to the protocol TypesetterFont. The only requirement of that protocol is that the object responds to the property name, so for example it could look like:

enum Font: String, TypesetterFont {
    case Regular = "MyFont-Regular"
    case Bold = "MyFont-Bold"

    var name: String { return rawValue }
}

Where "MyFont-Regular" is the name of the font you'd like to use.

Configuring

Typesetter can be passed a TypesetterConfiguration object where you can specify another path to your font sizes file.

Using Typesetter

Pass the bundle to initialize. Typesetter will look up the FontSizes file in the bundle and cache it for subsequent initializations in the same process:

let bundle = NSBundle(forClass: self.dynamicType)
let typesetter = Typesetter(bundle: bundle)

Typically, all you will then use is the sizedFontFor method, which you can use in two ways:

Using the TypesetterTextStyle enum

Remember the definition of Font from above? This is how to get a font sized according to your definitions and the users font size settings:

let sizedFont = typesetter.sizedFontFor(.Body, font: Font.Bold)

Using a string

This is a convenience method to be able to use Typesetter with @IBDesignable / @IBInspectable. Since @IBInspectable does not yet work with enum types, you can use the version of sizedFontFor without a type check like so:

let sizedFont = typesetter.sizedFontFor("Body", font: Font.Bold)

For an example involving @IBDesignable, go to the wiki

Contributions

Yes please!

About

A thin wrapper around dynamic type. Size your fonts across all accessibility sizes together with design

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published