Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active March 17, 2019 04:00
Show Gist options
  • Save laevandus/02e5a8e42c4967fd6d6048317a0c9f1f to your computer and use it in GitHub Desktop.
Save laevandus/02e5a8e42c4967fd6d6048317a0c9f1f to your computer and use it in GitHub Desktop.
extension UIFont.TextStyle {
public static let largeTitle: UIFont.TextStyle
public static let title1: UIFont.TextStyle
public static let title2: UIFont.TextStyle
public static let title3: UIFont.TextStyle
public static let headline: UIFont.TextStyle
public static let subheadline: UIFont.TextStyle
public static let body: UIFont.TextStyle
public static let callout: UIFont.TextStyle
public static let footnote: UIFont.TextStyle
public static let caption1: UIFont.TextStyle
public static let caption2: UIFont.TextStyle
}
let font = UIFont.preferredFont(forTextStyle: style)
// Automatically update font size when user changes preferred text size or accessibility text sizes.
label.adjustsFontForContentSizeCategory = true
label.font = font
// And the same behavior with buttons without attributed title.
button.titleLabel?.adjustsFontForContentSizeCategory = true
button.titleLabel?.font = font
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment