---
title: "preferredFont(forTextStyle:)"
framework: uikit
role: symbol
role_heading: Type Method
path: "uikit/uifont/preferredfont(fortextstyle:)"
---

# preferredFont(forTextStyle:)

Returns an instance of the system font for the specified text style with scaling for the user’s selected content size category.

## Declaration

```swift
class func preferredFont(forTextStyle style: UIFont.TextStyle) -> UIFont
```

## Parameters

- `style`: The text style for which to return a font. See doc://com.apple.uikit/documentation/UIKit/UIFont/TextStyle for recognized values.

## Mentioned in

Scaling fonts automatically

## Return Value

Return Value The system font associated with the specified text style.

## Discussion

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

- [Scaling fonts automatically](uikit/scaling-fonts-automatically.md)
- [Creating self-sizing table view cells](uikit/creating-self-sizing-table-view-cells.md)
- [preferredFont(forTextStyle:compatibleWith:)](uikit/uifont/preferredfont(fortextstyle:compatiblewith:).md)
- [UIFont.TextStyle](uikit/uifont/textstyle.md)
- [init(name:size:)](uikit/uifont/init(name:size:).md)
- [init(descriptor:size:)](uikit/uifont/init(descriptor:size:).md)
- [withSize(_:)](uikit/uifont/withsize(_:).md)
