FontFamily

public protocol FontFamily

Information about a font family. When an app specifies a custom font, they will implement an instance of FontFamily to fully describe that font.

  • Font family root name, e.g. “AvenirNext”

    Declaration

    Swift

    var familyName: String { get }
  • fontNameSuffix Default implementation

    Optional suffix to use for the font name.

    Used by FontFamily.fontName(for:compatibleWith:) e.g. “Italic” is a typical suffix for italic fonts. default = “”

    Default Implementation

    Declaration

    Swift

    var fontNameSuffix: String { get }
  • supportedWeights Default implementation

    All font weights supported by this font family (or those that you choose to bundle in your project).

    Defaults to all 9 font weights, but can be overridden in custom implementations of FontFamily. You must support at least one weight. This is used in the default implementation of accessibilityBoldWeight(for:)

    Default Implementation

    Declaration

    Swift

    var supportedWeights: [Typography.FontWeight] { get }
  • font(for:pointSize:compatibleWith:) Default implementation

    Returns a font for the specified weight and pointSize that is compatible with the traitCollection

    Default Implementation

    Declaration

    Swift

    func font(
        for weight: Typography.FontWeight,
        pointSize: CGFloat,
        compatibleWith traitCollection: UITraitCollection?
    ) -> UIFont

    Parameters

    weight

    desired font weight

    pointSize

    desired font point size

    traitCollection

    trait collection to consider (UITraitCollection.legibilityWeight). If nil then UIAccessibility.isBoldTextEnabled will be considered instead

  • fontName(for:compatibleWith:) Default implementation

    Generates a font name that can be used to initialize a UIFont. Not all fonts support all 9 weights.

    Default Implementation

    Declaration

    Swift

    func fontName(for weight: Typography.FontWeight, compatibleWith traitCollection: UITraitCollection?) -> String

    Parameters

    weight

    desired font weight

    traitCollection

    trait collection to consider (UITraitCollection.legibilityWeight). If nil then UIAccessibility.isBoldTextEnabled will be considered instead

    Return Value

    The font name formulated from familyName and weight

  • weightName(for:) Default implementation

    Generates a weight name suffix as part of a full font name. Not all fonts support all 9 weights.

    Default Implementation

    Declaration

    Swift

    func weightName(for weight: Typography.FontWeight) -> String

    Parameters

    weight

    desired font weight

    Return Value

    The weight name to use

  • accessibilityBoldWeight(for:) Default implementation

    Returns the alternate weight to use if user has requested a bold font. e.g. might convert .regular to .semibold. Not all fonts support all 9 weights.

    Default Implementation

    Declaration

    Swift

    func accessibilityBoldWeight(for weight: Typography.FontWeight) -> Typography.FontWeight

    Parameters

    weight

    desired font weight

    Return Value

    the alternate weight to use if user has requested a bold font. Should be heavier than weight if possible.

Default implementations

  • Determines whether the accessibility Bold Text feature is enabled within the given trait collection.

    If traitCollection is not nil, it checks for legibilityWeight == .bold. If traitCollection is nil, then it examines the system wide UIAccessibility setting of the same name.

    Declaration

    Swift

    public func isBoldTextEnabled(compatibleWith traitCollection: UITraitCollection?) -> Bool

    Parameters

    traitCollection

    the trait collection to evaluate (or nil to use system settings)

    Return Value

    true if the accessibility Bold Text feature is enabled.