Last active
March 13, 2019 04:13
-
-
Save marinofelipe/566cf6d7b379a02a1463561e935862bf to your computer and use it in GitHub Desktop.
Blog post / Dynamic Type - Defines scalable fonts behaviour and extends itself when conditionally conforms to raw representable of raw type string (what we use in our custom fonts)
This file contains 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 ScalableFont { | |
func scaled(forTextStyle textStyle: UIFont.TextStyle?, maxSize: CGFloat?) -> UIFont | |
} | |
extension UIFont: ScalableFont { | |
func scaled(forTextStyle textStyle: UIFont.TextStyle? = nil, maxSize: CGFloat? = nil) -> UIFont { | |
let fontMetrics = textStyle != nil ? UIFontMetrics(forTextStyle: textStyle!) : UIFontMetrics.default | |
if let maxSize = maxSize { | |
return fontMetrics.scaledFont(for: self, maximumPointSize: maxSize) | |
} | |
return fontMetrics.scaledFont(for: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment