Skip to content

Instantly share code, notes, and snippets.

@krummler
Last active April 15, 2020 10:55
Show Gist options
  • Save krummler/4fcad3881f527a82bc2a85cc2e453dd8 to your computer and use it in GitHub Desktop.
Save krummler/4fcad3881f527a82bc2a85cc2e453dd8 to your computer and use it in GitHub Desktop.
extension UIFont {
func with(style: UIFont.TextStyle, basePointSize: CGFloat, maxPointSize: CGFloat? = nil) -> UIFont {
if let maxPointSize = maxPointSize {
return UIFontMetrics(forTextStyle: style).scaledFont(for: self.withSize(basePointSize),
maximumPointSize: maxPointSize)
}
return UIFontMetrics(forTextStyle: style).scaledFont(for: self.withSize(basePointSize))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment