Skip to content

Instantly share code, notes, and snippets.

@ssebi
Created July 29, 2019 12:25
Show Gist options
  • Save ssebi/0109a48c56402244b298fdf9cbb4dd17 to your computer and use it in GitHub Desktop.
Save ssebi/0109a48c56402244b298fdf9cbb4dd17 to your computer and use it in GitHub Desktop.
Enable dynamic font with custom weight
extension UIFont {
@available(iOS 11.0, *)
static func preferredFont(for style: TextStyle, weight: Weight) -> UIFont {
let metrics = UIFontMetrics(forTextStyle: style)
let desc = UIFontDescriptor.preferredFontDescriptor(withTextStyle: style)
let font = UIFont.systemFont(ofSize: desc.pointSize, weight: weight)
return metrics.scaledFont(for: font)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment