Typesetter
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
Carthage:
ViaAdd the following your Cartfile:
github "ios-studio/Typesetter" ~> 0.1.3
CocoaPods:
ViaAdd the following your Podfile:
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:
TypesetterTextStyle
enum
Using the 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!