How to use the .monospaced system font design

It seems .monospaced font only applies when given a fixed size:

Text("monospaced")
  .font(.system(size: 14, design: .monospaced))

This won't work given a dynamic text style such as body. But as you've also mentioned it works fine for other fonts so this is probably a bug in Xcode 11.0 beta and hopefully will be fixed in next releases.


Update:

This issue was fixed with Xcode 11 beta 3. The following code works now:

Text("monospaced")
    .font(.system(.body, design: .monospaced))

In case you want to make only digits monospaced, you might try using something like this:

Text("0123456789")
    .font(Font.system(.body, design: .monospaced).monospacedDigit())

This does not circumvent the obvious bug of Xcode 11.0 beta, however. Letters are still not rendered monospaced.

Tags:

Ios

Swiftui