Contents

font(_:)

Sets the default font for text in the view.

Declaration

nonisolated func font(_ font: Font?) -> Text

Parameters

  • font:

    The font to use when displaying this text.

Mentioned in

Return Value

Text that uses the font you specify.

Discussion

Use font(_:) to apply a specific font to an individual Text View, or all of the text views in a container.

In the example below, the first text field has a font set directly, while the font applied to the following container applies to all of the text views inside that container:

VStack {
    Text("Font applied to a text view.")
        .font(.largeTitle)

    VStack {
        Text("These two text views have the same font")
        Text("applied to their parent view.")
    }
    .font(.system(size: 16, weight: .light, design: .default))
}

[Image]

See Also

Choosing a font