monospacedDigit
Modifies the fonts of all child views to use fixed-width digits, if possible, while leaving other characters proportionally spaced.
Declaration
compose().monospacedDigit()nonisolated func monospacedDigit() -> some ViewReturn value
A view whose child views' fonts use fixed-width numeric
Discussion
Using fixed-width digits allows you to easily align numbers of the same size in a table-like arrangement. This feature is also known as "tabular figures" or "tabular numbers."
This modifier only affects numeric characters, and leaves all other characters unchanged.
The following example shows the effect of monospacedDigit() on
multiple child views. The example consists of two VStack views
inside an HStack. Each VStack contains two Button views, with
the second VStack applying the monospacedDigit() modifier to its
contents. As a result, the digits in the buttons in the trailing
VStack are the same width, which in turn gives the buttons equal widths.
var body: some View {
HStack(alignment: .top) {
VStack(alignment: .leading) {
Button("Delete 111 messages") {}
Button("Delete 222 messages") {}
}
VStack(alignment: .leading) {
Button("Delete 111 messages") {}
Button("Delete 222 messages") {}
}
.monospacedDigit()
}
.padding()
.navigationTitle("monospacedDigit() Child Views")
}If a child view's base font doesn't support fixed-width digits, the font remains unchanged.
characters, while leaving other characters proportionally spaced.
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.
- fontSets the default font for text in this view.
- 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.