Contents

preferredFont(forTextStyle:compatibleWith:)

Returns an instance of the system font for the appropriate text style and traits.

Declaration

class func preferredFont(forTextStyle style: UIFont.TextStyle, compatibleWith traitCollection: UITraitCollection?) -> UIFont

Parameters

  • style:

    The text style for which to return a font. See Textstyle for recognized values.

  • traitCollection:

    The traits to use when determining which font to return.

Return Value

The system font associated with the specified text style and traits.

Discussion

To create a styled font based on a custom font, use a UIFontMetrics object.

Because fonts are immutable, any element that adjusts for an updated content size category does not modify the font itself. Instead, the element replaces the assigned font with a new instance based on the original settings.

See Also

Creating Fonts