font

Sets the default font for text in the view.

Text ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+font(_:) in SwiftUI

Declaration

React
compose().font(font: SwiftUI.Font | null)
Swift
nonisolated func font(_ font: Font?) -> Text

Parameters

  • font*SwiftUI.Font | null

    The font to use when displaying this text.

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))
}

See also

More in Text modifiers.