Declaration
compose().font(font: SwiftUI.Font | null)nonisolated func font(_ font: Font?) -> TextParameters
font*SwiftUI.Font | nullThe 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.
- accessibilityHeadingSets the accessibility level of this heading.
- accessibilityLabelAdds a label to the view that describes its contents.
- accessibilityTextContentTypeSets an accessibility text content type.
- baselineOffsetSets the vertical offset for the text relative to its baseline.
- boldApplies a bold font weight to the text.
- fontDesignSets the font design of the text.
- fontWeightSets the font weight of the text.
- fontWidthSets the font width of the text.
- foregroundStyleSets the style of the text displayed by this view.
- italicApplies italics to the text.
- kerningSets the spacing, or kerning, between characters.
- monospacedModifies the font of the text to use the fixed-width variant of the current font, if possible.