• Stars
    star
    297
  • Rank 140,075 (Top 3 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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.

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

For compatibility with Xcode version older than 13.3, I would recommend to checkout the 1.4.x tag, it should compile with Xcode 11 and greater

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.

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

App using this library

For maintainers

If you want to help maintaining this library, I would suggest to add this git hooks on pre-commit

In a terminal opened in the repo folder, executes these commands

echo '#!/bin/sh' > .git/hooks/pre-commit
echo '' >> .git/hooks/pre-commit
echo 'swiftlint' >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

More Repositories

1

Swift-Package-Manager-Static-Dynamic-Xcode-Bug

Workaround about SPM (Swift package manager) deal with Xcode 11.4 and Swift 5.2 with external static libraries. Adding an internal dynamic library to resolve static code duplication error
Swift
125
star
2

TellTime

iOS application to tell the time in the British way ๐Ÿ‡ฌ๐Ÿ‡งโฐ
Swift
64
star
3

SwiftUI-with-Size-Classes

Demonstrates how to deal with SwiftUI Size Class for iPhone, iPad Landscape and Portrait with SwiftUI
Swift
63
star
4

swift-tts

A straightforward package containing version for Swift modern concurrency, Point-Free Swift Dependency compatible with TCA and a Combine wrapper to provide Text to Speech (TTS) over AVFoundation/AVSpeechSynthesizer
Swift
37
star
5

swift-speech-recognizer

A straightforward Combine wrapper to provide Speech Recognition over SFSpeechRecognition
Swift
21
star
6

MixTeam

An old Swift project started in Swift 3 that I want to migrate to modern Swift, SwiftUI and at last publish it on the AppStore (which is done now :D).
Swift
11
star
7

MemoArt

A basic but smart SwiftUI pair-matching game. Continuously improving with some new art styles, new difficulty levels and some other user experience ideas.
Swift
8
star
8

steamScrum

Written in Swift for backend (Vapor) and using HTML+VanillaJS for frontend (With Milligram for styling purpose). Provide a simple interface to help team to do Poker Planning. Style WIP though.
Swift
6
star
9

SoliArt

An other Solitaire/Patience/Klondike game. This time in Swift with SwiftUI using TCA (The Composable Architecture). WIP
Swift
6
star
10

WeeklyRecipePlanning

Yet another recipe book app. But this one is made with SwiftUI, TCA (Composable Architecture) and CoreData
Swift
4
star
11

swift-ui-shape-maker

macOS application to draw your shape and directly convert it (in real time) to usable SwiftUI code that you can copy/paste to your codebase.
Swift
4
star
12

Pomme-s-Adventure

First tryout with SpriteKit
Swift
3
star
13

MarketingScreenshots

Automatically generate Screenshots for AppStore with XCUITests Test plans for multiple languages and everything is written in Swift
Swift
3
star
14

swift-past-ten

A Swift framework that telling the time passing a given time format (HH:mm) into "British"
Swift
2
star
15

HeuresCreuses

iOS, Apple Watch and macOS application that helps you find the best time to start your electric consuming devices like dishwasher or washing machine, it does the math for you to find the best delay for your programs.
Swift
2
star