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:
01:11
the total length of the string is smaller than (let's say) 00:00
and the text is displaced..trailing
or .center
don't fix the jiggling....
that appears from time to time. I can fix it by adding a whitespace at the end of the String
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)
}
You can tell it to use monospace digits like this:
Text(String(format: "%02d:%02d", hours, minutes))
.font(Font.body.monospacedDigit())
.frame(width: 100, alignment: .trailing)
You can substitute "Font.body" with your preferred Font.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With