monospacedDigit()
Returns a modified font that uses fixed-width digits, while leaving other characters proportionally spaced.
Declaration
func monospacedDigit() -> FontReturn Value
A font that uses fixed-width numeric characters.
Discussion
This modifier only affects numeric characters, and leaves all other characters unchanged. If the base font doesn’t support fixed-width, or monospace digits, the font remains unchanged.
The following example shows two text fields arranged in a VStack. Both text fields specify the 12-point system font, with the second adding the monospacedDigit() modifier to the font. Because the text includes the digit 1, normally a narrow character in proportional fonts, the second text field becomes wider than the first.
@State private var userText = "Effect of monospacing digits: 111,111."
var body: some View {
VStack {
TextField("Proportional", text: $userText)
.font(.system(size: 12))
TextField("Monospaced", text: $userText)
.font(.system(size: 12).monospacedDigit())
}
.padding()
.navigationTitle(Text("Font + monospacedDigit()"))
}[Image]