Code snippets for the blog post "The font of all... well, some knowledge"
Last active
March 25, 2017 22:51
-
-
Save warren-gavin/726aace038f04f3b39bbda0b62c2b084 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol CustomDynamicTypeable { | |
func preferredFont(forTextStyle style: UIFontTextStyle) -> UIFont? | |
func font(forSize pointSize: CGFloat) -> UIFont? | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum JudsonFont: String, CustomDynamicTypeable { | |
case regular = "Judson-Regular" | |
case bold = "Judson-Bold" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let font = JudsonFont.regular.preferredFont(forTextStyle: .body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment