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

More usage patterns

Beat edited this page Feb 7, 2016 · 1 revision

In order to avoid shotgun surgery in the event you may want to change usage of Typesetter, write an adapter:

class FontAdapter {
   private let typesetter = Typesetter(bundle: NSBundle(forClass: FontAdapter.self))
   
   func sizedFontFor(textStyle: TypesetterTextStyle, font: TypesetterFont) -> UIFont {
       return typesetter.sizedFontFor(textStyle, font: font)
   }
}

If you're a fan of extensions, here's how to extend UIFont:

extension UIFont {
    convenience init(textStyle: TypesetterTextStyle, font: TypesetterFont) {
        let font = FontAdapter().sizedFontFor(textStyle, font: font)
        self.init(descriptor: font.fontDescriptor(), size: font.pointSize)
    }
}
Clone this wiki locally