Skip to content

Instantly share code, notes, and snippets.

@warren-gavin
Last active March 25, 2017 22:51
Show Gist options
  • Save warren-gavin/726aace038f04f3b39bbda0b62c2b084 to your computer and use it in GitHub Desktop.
Save warren-gavin/726aace038f04f3b39bbda0b62c2b084 to your computer and use it in GitHub Desktop.
protocol CustomDynamicTypeable {
func preferredFont(forTextStyle style: UIFontTextStyle) -> UIFont?
func font(forSize pointSize: CGFloat) -> UIFont?
}
extension CustomDynamicTypeable where Self: RawRepresentable, Self.RawValue == String {
func preferredFont(forTextStyle style: UIFontTextStyle) -> UIFont? {
let font = UIFont.preferredFont(forTextStyle: style)
return UIFont(name: rawValue, size: font.pointSize)
}
func font(forSize pointSize: CGFloat) -> UIFont? {
return UIFont(name: rawValue, size: pointSize)
}
}
enum JudsonFont: String, CustomDynamicTypeable {
case regular = "Judson-Regular"
case bold = "Judson-Bold"
}
let font = JudsonFont.regular.preferredFont(forTextStyle: .body)

Code snippets for the blog post "The font of all... well, some knowledge"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment