<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIFont/preferredFont(forTextStyle:compatibleWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIFont(cm)preferredFontForTextStyle:compatibleWithTraitCollection:"
  },
  "title" : "preferredFont(forTextStyle:compatibleWith:)"
}
-->

# preferredFont(forTextStyle:compatibleWith:)

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

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

## Parameters

`style`

The text style for which to return a font. See [`UIFont.TextStyle`](/documentation/UIKit/UIFont/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`](/documentation/UIKit/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.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)