RSDFontRules

open class RSDFontRules

The font rules object is a concrete implementation of the design rules used for a given version of the SageResearch frameworks. A module can use this class as-is or override the class to enforce a set of rules pinned to the tasks included within a module. This is important to allow a module to be validated against a given UI/UX. The frameworks can later change to reflect new devices, OS changes, and design system updates to incorporate the results of more design studies.

  • The version for the font rules. If the design rules change with future versions of this framework, then the current version number should be rev’d as well and any changes to this rule set that are not additive include logic to return the previous rules associated with a previous version.

    Declaration

    Swift

    open private(set) var version: Int {
      get
      }
  • On iOS and tvOS, this method allows for using a different font size depending upon the trait collection. Default implementation calls through to font(for:) but a module that is designed to run on an iPad or Apple TV could use this method to define a different set of fonts for those devices.

    Note

    If future versions of the Sage Design System include a different set of fonts for iPad or Apple TV devices, this method should check for version and return the current implementation for the version before the version that is being implemented.

    Declaration

    Swift

    @available(iOS 10.3, tvOS 10.2, *)
    open func font(for textType: RSDDesignSystem.TextType, compatibleWith traitCollection: UITraitCollection?) -> RSDFont

    Parameters

    textType

    The text type for the font.

    traitCollection

    The trait collection for the label or button.

    Return Value

    The font to use for this text.

  • Returns the font to use for the given button type and state.

    Declaration

    Swift

    open func buttonFont(for buttonType: RSDDesignSystem.ButtonType, state: RSDControlState) -> RSDFont

    Parameters

    buttonType

    The button type.

    state

    The button state.

    Return Value

    The font to use for this text.

  • Returns the font to use for a given text type.

    Declaration

    Swift

    open func font(for textType: RSDDesignSystem.TextType) -> RSDFont

    Parameters

    textType

    The text type for the font.

    Return Value

    The font to use for this text.

  • Returns a font in the given size and weight in the font family specified for this design. Typically, you will want to use font(for textType: RSDDesignSystem.TextType) instead for copy and dynamic text. This method should only be used where the design calls for a specific size to match the graphic design of the view.

    Note

    All other methods on this class will call through to this method, so for custom fonts, you can override this method only if the only change is a custom font.

    Declaration

    Swift

    open func font(ofSize fontSize: CGFloat, weight: RSDFont.Weight = .regular) -> RSDFont

    Parameters

    fontSize

    The font size.

    weight

    The font weight.

    Return Value

    The font to use for this size and weight.

  • Returns an italic font in the given size and weight in the font family specified for this design. Typically, you will want to use font(for textType: RSDDesignSystem.TextType) instead for copy and dynamic text. This method should only be used where the design calls for a specific size to match the graphic design of the view.

    Note

    All other methods on this class will call through to this method, so for custom fonts, you can override this method only if the only change is a custom font.

    Declaration

    Swift

    open func italicFont(ofSize fontSize: CGFloat, weight: RSDFont.Weight = .regular) -> RSDFont

    Parameters

    fontSize

    The font size.

    weight

    The font weight.

    Return Value

    The font to use for this size and weight.

  • Returns the base font for a given text type. This is the font size defined in the Sage Design System table. For dynamic fonts, this can be resized based upon user preferences by using the font(for textType: RSDDesignSystem.TextType) instead.

    This is only to be used directly where the text needs to fix within a specific size, but match the style of a given text type.

    Declaration

    Swift

    open func baseFont(for textType: RSDDesignSystem.TextType) -> RSDFont

    Parameters

    textType

    The text type for the font.

    Return Value

    The base font to use for this text.

  • Using a mapping of the base font size, look for the text style to use for that text type and return the font size ratio preferred by the user based on their accessibility settings.

    Declaration

    Swift

    open func preferredFontSizeRatio(for textType: RSDDesignSystem.TextType, compatibleWith traitCollection: UITraitCollection? = nil) -> CGFloat

    Parameters

    textType

    The text type for the font.

    Return Value

    The ratio of preferred font size to base font size.