Any idea to avoid the jiggling below? The code is something like this:
Text(format: "%02d:%02d", hours, minutes)
.frame(width: 100, alignment: .trailing)
(The frame is bigger than the string)
NOTES:
- The problem is that "1" is thinner than "0" so when I hit a combination like
01:11
the total length of the string is smaller than (let's say)00:00
and the text is displaced. - Fixing the frame width has no effect on the jiggling.
- Alignment
.trailing
or.center
don't fix the jiggling. - I am curious about the
...
that appears from time to time. I can fix it by adding a whitespace at the end of theString
like this"%02d:%02d "
The slider code (for completion):
Slider(value: $totalTime, in: 0...9).frame(width: 150)
The conversion from Slider value to hh:mm:
func formatTime(_ time: Float) -> String {
let hours: Int = Int(time)
let minutes: Int = Int(time.truncatingRemainder(dividingBy: 1.0) * 60)
return String(format: "%02d:%02d", hours, minutes)
}