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.

Overview

SwiftClockUI

Xcode Unit Test

Clock UI for SwiftUI

This library has been tested

  • βœ… πŸ’» macOS Catalina 10.15.3
  • βœ… πŸ’» macOS Big Sur 11.6
  • βœ… πŸ“± iOS 13
  • βœ… πŸ“± iOS 14
  • βœ… πŸ“± iOS 15

Bind a date

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

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

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:

Style Picture
Classic Clock View with Classic style
Art Nouveau Clock View with Art Nouveau style
Drawing Clock View with Drawing style
Steampunk Clock View with Steampunk style

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)
    }
}

\.clockStyle is typed as enum ClockStyle which is Identifiable, CaseIterable, and has a convenient method to get the description (in English): public var description: String

It's very useful when you want to iterate over this enum to let the user choose the clock style, for instance you can easily do something like this:

struct StylePicker: View {
    @Binding var clockStyle: ClockStyle

    var body: some View {
        Picker("Style", selection: clockStyle) {
            ForEach(ClockStyle.allCases) { style in
                Text(style.description).tag(style)
            }
        }
        .pickerStyle(SegmentedPickerStyle())
    }
}

Change elements color

You can also change the color of Clock elements. Again with changing some .environment keys.

ClockView()
    .environment(\.clockArmColors, ClockArmColors(
        minute: .red,
        hour: .blue
    ))
    .environment(\.clockBorderColor, .orange)
    .environment(\.clockIndicatorsColor, .green)

In light mode, you could expect a result like this:

Clock View with Classic style and some colors changed

Installation

Xcode

You can add SwiftToTen to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Swift Packages β€Ί Add Package Dependency...
  2. Enter "https://github.com/renaudjenny/SwiftClockUI" into the package repository URL test field

As package dependency

Edit your Package.swift to add this library.

", dependencies: ["SwiftClockUI"]), ... ] ) ">
let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/renaudjenny/SwiftClockUI", from: "1.4.0"),
        ...
    ],
    targets: [
        .target(
            name: "
   
    "
   ,
            dependencies: ["SwiftClockUI"]),
        ...
    ]
)

App using this library

You might also like...
Building a better date/time library for Swift

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.
A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your most suitable time zone.

TimeZonePicker A TimeZonePicker UIViewController similar to the iOS Settings app. Search and select from a range of cities and countries to find your

A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Time is a Swift package that makes dealing with calendar values a natural and straight-forward process.

Time Time is a Swift package that makes dealing with calendar values a natural and straight-forward process. Working with calendars can be extremely c

NVDate is an extension of NSDate class (Swift4), created to make date and time manipulation easier.

NVDate is an extension of NSDate class (Swift4), created to make date and time manipulation easier. NVDate is testable and robust, we wrote intensive test to make sure everything is safe.

Custom Time Picker ViewController with Selection of start and end times in Swift πŸ”Ά
Custom Time Picker ViewController with Selection of start and end times in Swift πŸ”Ά

LFTimePicker Custom Time Picker ViewController with Selection of start and end times in Swift πŸ”Ά . Based on Adey Salyard's design @ Dribbble One to tw

Time Lines - Know when all your friends, colleagues, and family are
Time Lines - Know when all your friends, colleagues, and family are

Time Lines Know when all your friends, colleagues, and family are. Time Lines is a practical app to know when all your friends, colleagues and family

Date and time manager for iOS/OSX written in Swift
Date and time manager for iOS/OSX written in Swift

Tempo was designed to work both in OSX and in iOS (7.0+). Work with the time or dates can be cumbersome, iOS development. Tempo allows you to deal easly with date and time. Basics manipulations are already implemented in Tempo.

Swifty Date & Time API inspired from Java 8 DateTime API.

AnyDate Swifty Date & Time API inspired from Java 8 DateTime API. Background I think that date & time API should be easy and accurate. Previous dates,

Comments
Releases(2.0.0)
Owner
Renaud Jenny
Renaud Jenny
Simple clock app for the different time zones.

DunyaSaatleri The clock app provide the user adding clocks of cities from different timezones. The times showed by analog clock. The added clocks can

Ozan Barış GÜNAYDIN 1 Nov 27, 2021
The goal is a simple iOS app that draws an analog clock of the current time

Qrono This is a work-in-progress. The goal is a simple iOS app that draws an analog clock of the current time (as well as displaying a digital readout

Justin Reusch 2 Jan 29, 2022
SwiftDate πŸ” Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift.

Toolkit to parse, validate, manipulate, compare and display dates, time & timezones in Swift. What's This? SwiftDate is the definitive toolchain to ma

Daniele Margutti 7.2k Jan 4, 2023
Population Clock is an iOS tool for learning about geography and demographics.

PopulationClock Population Clock is an iOS tool for learning about geography and demographics. Download app on iTunes The project uses the most recent

Netfilter 12 Feb 8, 2022
A clock for iOS based off of the famous fibonacci sequence

Fibonacc iClock Fibonacc iClock is a fibonacci clock implementation for iOS. This project is based off of Thiago SΓ‘'s implementation of Philippe ChrΓ©t

null 10 Dec 16, 2022
A minimal hexadecimal clock for the Apple TV.

Hex Color Clock A simple, minimal hexadecimal clock for the Apple TV. Download it on the App Store! Dependencies Fastlane is used to manage the build

Colin Drake 17 Jul 19, 2022
This app will hlep you realize if the job you are doing, truly is worth your time

Worth Your Time Is working for your current pay really worth your time? This app will hlep you realize if the job you are doing, truly is worth your t

Phillip Lundin 2 Mar 1, 2022
A "time ago", "time since", "relative date", or "fuzzy date" category for NSDate and iOS, Objective-C, Cocoa Touch, iPhone, iPad

Migration 2014.04.12 NSDate+TimeAgo has merged with DateTools. DateTools is the parent project and Matthew York is the project head. This project is n

Kevin Lawler 1.8k Dec 2, 2022
SwiftMoment - A time and calendar manipulation library for iOS 9+, macOS 10.11+, tvOS 9+, watchOS 2+ written in Swift 4.

SwiftMoment This framework is inspired by Moment.js. Its objectives are the following: Simplify the manipulation and readability of date and interval

Adrian Kosmaczewski 1.6k Dec 31, 2022
Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS.

Timekeeper is an easy-to-use time measurement library written in Swift, with support for iOS, tvOS, watchOS and macOS. Installation Timekee

Andreas Pfurtscheller 1 Oct 18, 2021