Monospaced is your best option. This makes a monospaced version of the current font
struct ClockView: View {
@State private var date: String = "00:00:00"
var body: some View {
ZStack {
Color.black
.edgesIgnoringSafeArea(.all)
Text(date)
.foregroundColor(.white)
.font(.system(size: 45, weight: .ultraLight, design: .default).monospaced())
.foregroundColor(.secondary)
.onReceive(ClockView.timer) { _ in
self.date = ClockView.timeFormat.string(from: Date())
}
}
}
static let timer = Timer.publish(every: 0.2, on: .main, in: .common).autoconnect()
static var timeFormat: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "HH:mm:ss"
return formatter
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: