4

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

sash
  • 8,423
  • 5
  • 63
  • 74
  • I've run into this problem in my own project and found no proper solution. Even if you do `Text(date, style: .timer).frame(minWidth: 200).background(Color.green)` you can see that the view is plenty wide but the text is still truncated as the timer counts up. It seems reasonable to assume it's a bug in Apple's beta code. I've filed a bug in Feedback Assistant and I encourage you to do the same. – Jamie A Aug 26 '20 at 07:47

2 Answers2

0

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

Text(Date(), style: .timer)
   .font(Font.system(size: 16).monospacedDigit())
Asperi
  • 228,894
  • 20
  • 464
  • 690
0

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.

Jamie A
  • 881
  • 1
  • 6
  • 14
  • Still not fixed in the release. Have to make font size decision on my own. Määäähhhh – Tob Oct 24 '20 at 11:07