SwiftUI library to display a clock. You can move the arms to change the time, change the style of the clock and customise some configurations.

Clock UI for SwiftUI

This library has been tested

  • ✅💻 macOS Catalina 10.15.3
  • ✅📱 iOS 13.3
  • ✅📱 iOS 14.0 Beta (some snapshots tests are failing but they are all correct 😅)

Bind a date

struct ContentView: View {
    @State private var date = Date()

    var body: some View {
        ClockView().environment(\.clockDate, $date)
    }
}

Swift

Simply set .environment(\.clockDate, $date) $date has to be a binding.

If you want something constant (just for showing the time), you could pass .constant(yourDate)

  • Arms move when date are set (take hour and minute in account)
  • Move the Arms change the date (hour and minute depending on which arm you’ve moved)

Change Clock style

There is 4 different clock style:

STYLEPICTUREClassicClockViewClassicArt NouveauClockViewArtNouveauDrawingClockViewDrawingSteampunkClockViewSteampunk

To set the style: .environment(\.clockStyle, .steampunk) for Steampunk style for instance.

struct ContentView: View {
    @State private var clockStyle: ClockStyle = .classic

    var body: some View {
        ClockView().environment(\.clockStyle, clockStyle)
    }
}

#clock #swiftui

A Clock UI for SwiftUI
8.70 GEEK