Post

Replies

Boosts

Views

Activity

Digits move sideways
I’m new to SwiftUI programming and am following a tutorial on how to make a digital clock. My problem is that the digits move slightly side ways as they update. I found someone suggesting using a invisible dummy text to control it but it’s not working for me. I don’t want to use a mono spaced text. Any suggestions? struct ContentView: View { @State var date = Date() var body: some View { ZStack { //Background color Color.black .edgesIgnoringSafeArea(.all) //Dummy text set to be slightly visible for reference Text("00:00:00").opacity(0.3) .foregroundColor(.accentColor) .font(.system(size: 50, weight: .ultraLight, design: .default)) } } var timeFormat: DateFormatter { let formatter = DateFormatter() formatter.dateFormat = "HH:mm:ss" return formatter } func timeString(date: Date) -> String { let time = timeFormat.string(from: date) return time } var updateTimer: Timer { Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: {_ in self.date = Date() }) } }
6
0
825
Jan ’22