SwiftUI Text with timer style gets truncated

Viewed 660

When using Text with style .timer the time is truncated at certain times during the countdown. Setting frame, fixedSize, layoutPriority, padding didn't help. The following code:

struct ContentView: View {
    var body: some View {
        Text(Date(), style: .timer)
    }
}

will display: O:00, O:01, O:02, O:03,O:... (gets truncated), O:05 etc.

enter image description here

Any ideas how to fix it?

There are similar question like this, but they didn't help:

Text inside a VStack truncates when it's not supposed to in SwiftUI

SwiftUI Text Behavior

2 Answers

Works with monospaced style. Tested with Xcode 12b3 / iOS 14.

Text(Date(), style: .timer)
   .font(Font.system(size: 16).monospacedDigit())

This was a bug in Apple's code, which has since been fixed. When building with Xcode 12 beta 6 / running on iOS 14 beta 6, the timer will not truncate.

Related