Declaration
compose().font(font: SwiftUI.Font | null)nonisolated func font(_ font: Font?) -> some ViewParameters
font*SwiftUI.Font | nullThe default font to use in this view.
Return value
A view with the default font set to the value you supply.
Discussion
Use font(_:) to apply a specific font to all of the text in a view.
The example below shows the effects of applying fonts to individual views and to view hierarchies. Font information flows down the view hierarchy as part of the environment, and remains in effect unless overridden at the level of an individual view or view container.
Here, the outermost VStack applies a 16-point system font as a
default font to views contained in that VStack. Inside that stack,
the example applies a Font.largeTitle font to just the first text
view; this explicitly overrides the default. The remaining stack and the
views contained with it continue to use the 16-point system font set by
their containing view:
VStack {
Text("Font applied to a text view.")
.font(.largeTitle)
VStack {
Text("These 2 text views have the same font")
Text("applied to their parent hierarchy")
}
}
.font(.system(size: 16, weight: .light, design: .default))See also
More in Text and symbols.
- allowsTighteningSets whether text in this view can compress the space between characters when necessary to fit text in a line.
- autocorrectionDisabledSets whether to disable autocorrection for this view.
- baselineOffsetSets the vertical offset for the text relative to its baseline in this view.
- boldApplies a bold font weight to the text in this view.
- findDisabledPrevents find and replace operations in a text editor.
- findNavigatorProgrammatically presents the find and replace interface for text editor views.
- fontDesignSets the font design of the text in this view.
- fontWeightSets the font weight of the text in this view.
- fontWidthSets the font width of the text in this view.
- interactionActivityTrackingTagSets a tag that you use for tracking interactivity.
- italicApplies italics to the text in this view.
- kerningSets the spacing, or kerning, between characters for the text in this view.