Skip to content

Instantly share code, notes, and snippets.

@hoppsen
Last active January 27, 2023 18:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoppsen/6b752057b98fa7527ee1f4d4ba05fef0 to your computer and use it in GitHub Desktop.
Save hoppsen/6b752057b98fa7527ee1f4d4ba05fef0 to your computer and use it in GitHub Desktop.
UIFont extension for (the gradual introduction of) Dynamic Type Sizes, but only enabled in DEBUG mode.
//
// UIFont+DynamicTypeSizes.swift
//
// https://gist.github.com/hoppsen/6b752057b98fa7527ee1f4d4ba05fef0
//
// More about Apple's Typography can be found here:
// https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/typography/
import UIKit
extension UIFont {
/// SFProDisplay, Regular, 34pt
static let largeTitle: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .largeTitle)
#else
return UIFont.systemFont(ofSize: 34.0, weight: .regular)
#endif
}()
/// SFProDisplay, Regular, 28pt
static let title1: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .title1)
#else
return UIFont.systemFont(ofSize: 28.0, weight: .regular)
#endif
}()
/// SFProDisplay, Regular, 22pt
static let title2: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .title2)
#else
return UIFont.systemFont(ofSize: 22.0, weight: .regular)
#endif
}()
/// SFProDisplay, Regular, 20pt
static let title3: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .title3)
#else
return UIFont.systemFont(ofSize: 20.0, weight: .regular)
#endif
}()
/// SFProText, Semibold, 17pt
static let headline: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .headline)
#else
return UIFont.systemFont(ofSize: 17.0, weight: .semibold)
#endif
}()
/// SFProText, Regular, 17pt
static let body: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .body)
#else
return UIFont.systemFont(ofSize: 17.0, weight: .regular)
#endif
}()
/// SFProText, Regular, 16pt
static let callout: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .callout)
#else
return UIFont.systemFont(ofSize: 16.0, weight: .regular)
#endif
}()
/// SFProText, Regular, 15pt
static let subheadline: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .subheadline)
#else
return UIFont.systemFont(ofSize: 15.0, weight: .regular)
#endif
}()
/// SFProText, Regular, 13pt
static let footnote: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .footnote)
#else
return UIFont.systemFont(ofSize: 13.0, weight: .regular)
#endif
}()
/// SFProText, Regular, 12pt
static let caption1: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .caption1)
#else
return UIFont.systemFont(ofSize: 12.0, weight: .regular)
#endif
}()
/// SFProText, Regular, 11pt
static let caption2: UIFont = {
#if DEBUG
return UIFont.preferredFont(forTextStyle: .caption2)
#else
return UIFont.systemFont(ofSize: 11.0, weight: .regular)
#endif
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment