Typography

public struct Typography

Represents a font as it would appear in a design document

  • Information about the font family

    Declaration

    Swift

    public let fontFamily: FontFamily
  • Font weight

    Declaration

    Swift

    public let fontWeight: FontWeight
  • Font size (aka point size)

    Declaration

    Swift

    public let fontSize: CGFloat
  • Line height (typically greater than font size)

    Declaration

    Swift

    public let lineHeight: CGFloat
  • Letter spacing (in points, not percentage)

    Declaration

    Swift

    public let letterSpacing: CGFloat
  • Paragraph indent (in points)

    Declaration

    Swift

    public let paragraphIndent: CGFloat
  • Paragraph spacing (in points)

    Declaration

    Swift

    public let paragraphSpacing: CGFloat
  • Text case

    Declaration

    Swift

    public let textCase: TextCase
  • Text decoration (none, underline, or strikethrough)

    Declaration

    Swift

    public let textDecoration: TextDecoration
  • The text style (e.g. Body or Title) that this font most closely represents. Used for Dynamic Type scaling of the font

    Declaration

    Swift

    public let textStyle: UIFont.TextStyle
  • Whether this font is fixed in size or should be scaled through Dynamic Type

    Declaration

    Swift

    public let isFixed: Bool
  • The factory to use to convert from family name + font style into a FontFamily. The default is to use DefaultFontFamilyFactory.

    If you use a custom font family (or families) in your project, create your own factory to return the correct font family and then set it here, preferably as early as possible in the app launch lifecycle.

    Declaration

    Swift

    public static var factory: FontFamilyFactory
  • Initializes a typography instance with the specified parameters

    Declaration

    Swift

    public init(
        fontFamily: FontFamily,
        fontWeight: FontWeight,
        fontSize: CGFloat,
        lineHeight: CGFloat,
        letterSpacing: CGFloat = 0,
        paragraphIndent: CGFloat = 0,
        paragraphSpacing: CGFloat = 0,
        textCase: TextCase = .none,
        textDecoration: TextDecoration = .none,
        textStyle: UIFont.TextStyle = .body,
        isFixed: Bool = false
    )

    Parameters

    fontFamily

    font family to use

    fontWeight

    font weight to use

    fontSize

    font size to use

    lineHeight

    line height to use

    letterSpacing

    letter spacing to use (defaults to 0)

    paragraphIndent

    paragraph indent to use (defaults to 0)

    paragraphSpacing

    paragraph spacing to use (defaults to 0)

    textCase

    text case to apply (defaults to .none)

    textDecoration

    text decoration to apply (defaults to .none)

    textStyle

    text style to use for scaling (defaults to .body)

    isFixed

    true if this font should never scale, false if it should scale (defaults to .false)

  • Initializes a typography instance with the specified parameters

    Declaration

    Swift

    public init(
        familyName: String,
        fontStyle: FontStyle = .regular,
        fontWeight: FontWeight,
        fontSize: CGFloat,
        lineHeight: CGFloat,
        letterSpacing: CGFloat = 0,
        paragraphIndent: CGFloat = 0,
        paragraphSpacing: CGFloat = 0,
        textCase: TextCase = .none,
        textDecoration: TextDecoration = .none,
        textStyle: UIFont.TextStyle = .body,
        isFixed: Bool = false
    )

    Parameters

    familyName

    font family name

    fontStyle

    font style (defaults to regular)

    fontWeight

    font weight to use

    fontSize

    font size to use

    lineHeight

    line height to use

    letterSpacing

    letter spacing to use (defaults to 0)

    paragraphIndent

    paragraph indent to use (defaults to 0)

    paragraphSpacing

    paragraph spacing to use (defaults to 0)

    textCase

    text case to apply (defaults to .none)

    textDecoration

    text decoration to apply (defaults to .none)

    textStyle

    text style to use for scaling (defaults to .body)

    isFixed

    true if this font should never scale, false if it should scale (defaults to .false)

  • The nine basic font weights. Not all fonts support all 9 weights.

    See more

    Declaration

    Swift

    public enum FontWeight : CGFloat, CaseIterable
  • Information about the system font family

    Declaration

    Swift

    static let systemFamily: FontFamily
  • Font style (used together with font family name and font weight to load a specific font)

    See more

    Declaration

    Swift

    public enum FontStyle : String, CaseIterable
  • Capitalization to be applied to user-facing text

    See more

    Declaration

    Swift

    public enum TextCase : String, CaseIterable
  • Decoration to be applied

    See more

    Declaration

    Swift

    public enum TextDecoration : String, CaseIterable
  • Line mode (single or multi)

    See more

    Declaration

    Swift

    public enum LineMode
  • Generates the font and auxilliary layout information needed to render the Typography

    maximumPointSize will have no effect for fixed Typographies (isFixed = true).

    Declaration

    Swift

    public func generateLayout(
        maximumPointSize: CGFloat? = nil,
        compatibleWith traitCollection: UITraitCollection?
    ) -> TypographyLayout

    Parameters

    maximumPointSize

    (optional) maximum point size for Dynamic Type, default = nil, means no maximum

    traitCollection

    trait collection to apply (looking for preferredContentSizeCategory and legibilityWeight)

    Return Value

    Font and various styles used to render the Typography

  • Generates the font and auxilliary layout information needed to render the Typography

    maximumScaleFactor will have no effect for fixed Typographies (isFixed = true).

    Declaration

    Swift

    public func generateLayout(
        maximumScaleFactor: CGFloat,
        compatibleWith traitCollection: UITraitCollection?
    ) -> TypographyLayout

    Parameters

    maximumScaleFactor

    (optional) maximum scale factor for Dynamic Type, e.g. 2.0 for a 16 pt font would mean limit maximum point size to 32 pts.

    traitCollection

    trait collection to apply (looking for preferredContentSizeCategory and legibilityWeight)

    Return Value

    Font and various styles used to render the Typography

  • Returns a copy of the Typography but with the new familyName applied.

    Declaration

    Swift

    func familyName(_ value: String) -> Typography

    Parameters

    value

    the family name to use

    Return Value

    an updated copy of the Typography

  • Returns a copy of the Typography but with .regular font weight

    Declaration

    Swift

    var regular: Typography { get }
  • Returns a copy of the Typography but with .bold font weight

    Declaration

    Swift

    var bold: Typography { get }
  • Returns a copy of the Typography but with the new fontWeight applied.

    Declaration

    Swift

    func fontWeight(_ value: FontWeight) -> Typography

    Parameters

    value

    the font weight to use

    Return Value

    an updated copy of the Typography

  • Returns a copy of the Typography but with the new fontSize applied.

    Declaration

    Swift

    func fontSize(_ value: CGFloat) -> Typography

    Parameters

    value

    the font size to use

    Return Value

    an updated copy of the Typography

  • Returns a copy of the Typography but with the new lineHeight applied.

    Declaration

    Swift

    func lineHeight(_ value: CGFloat) -> Typography

    Parameters

    value

    the line height to use

    Return Value

    an updated copy of the Typography

  • Returns a copy of the Typography but with isFixed set to true

    Declaration

    Swift

    var fixed: Typography { get }
  • Returns a copy of the Typography but with the new letterSpacing applied.

    Declaration

    Swift

    func letterSpacing(_ value: CGFloat) -> Typography

    Parameters

    value

    the letter spacing to use

    Return Value

    an updated copy of the Typography

  • Returns a copy of the Typography but with the new textCase applied.

    Declaration

    Swift

    func textCase(_ value: TextCase) -> Typography

    Parameters

    value

    the text case to use

    Return Value

    an updated copy of the Typography

  • Returns a copy of the Typography but with the new textDecoration applied.

    Declaration

    Swift

    func decoration(_ value: TextDecoration) -> Typography

    Parameters

    value

    the text decoration to use

    Return Value

    an updated copy of the Typography

  • The multiple used to generate line heights from standard or system font sizes (130%)

    Declaration

    Swift

    public static let systemLineHeightMultiple: CGFloat
  • Standard typography for labels (uses the system font)

    Declaration

    Swift

    public static let systemLabel: Typography
  • Standard typography for buttons (uses the system font)

    Declaration

    Swift

    public static let systemButton: Typography
  • Typography for the system font

    Declaration

    Swift

    @available(iOS 14, *)
    @available(tvOS, unavailable)
    public static let system: Typography
  • Typography for the small system font

    Declaration

    Swift

    @available(iOS 14, *)
    @available(tvOS, unavailable)
    public static let smallSystem: Typography