Skip to content

VentanYu/TimePicker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🕒 TimePicker

A lightweight, customizable SwiftUI time picker component for selecting hours, minutes, and seconds — designed for modern iOS apps that value clarity, animation, and minimalism.
Built purely with SwiftUI and fully documented in Apple’s documentation style.


🧭 Definition

TimePicker provides a smooth, wheel-style time selection interface with optional background customization.
It’s ideal for scenarios such as:

  • Timers and stopwatches
  • Scheduling features
  • Input for durations or countdowns

This package includes:

  • TimePicker: A fully customizable SwiftUI view.
  • .timePicker(...): A modifier for presenting the picker in a sheet.
  • Internal helpers (PickerWithoutIndicator, RemovePickerIndicator) for a clean, minimal design.

📦 Installation

🧰 Swift Package Manager (Recommended)

  1. In Xcode, open File ▸ Add Packages...
  2. Paste the package URL:
    https://github.com/ThakurVijay2191/TimePicker.git
    
  3. Select the latest version and add it to your app target.

Alternatively, add it directly to your Package.swift:

dependencies: [
    .package(url: "https://github.com/ThakurVijay2191/TimePicker.git", from: "1.0.0")
]

💻 Usage

1. Basic Example

import SwiftUI
import TimePicker

struct ContentView: View {
    @State private var showPicker = false
    @State private var hours = 0
    @State private var minutes = 0
    @State private var seconds = 0

    var body: some View {
        VStack(spacing: 20) {
            Text("Selected Time: \(hours)h \(minutes)m \(seconds)s")
                .font(.headline)

            Button("Select Time") {
                showPicker = true
            }
            .timePicker(
                isPresented: $showPicker,
                style: .init(.bar),
                hours: $hours,
                minutes: $minutes,
                seconds: $seconds
            )
        }
        .padding()
    }
}

2. Direct Usage

TimePicker(
    style: .init(.bar),
    hours: $hours,
    minutes: $minutes,
    seconds: $seconds
)

You can embed this directly inside custom layouts or modals — it’s not limited to sheets.


📱 Preview

Screen.Recording.2025-10-28.at.3.24.24.PM.mov

🎨 Customization

Parameter Type Description
style AnyShapeStyle Custom background fill (e.g., .bar, .thinMaterial, .ultraThickMaterial, or gradient).
hours Binding<Int> Bound variable for hour selection.
minutes Binding<Int> Bound variable for minute selection.
seconds Binding<Int> Bound variable for second selection.

Example:

TimePicker(
    style: .init(.ultraThickMaterial),
    hours: $hours,
    minutes: $minutes,
    seconds: $seconds
)

🧩 Features

  • 🔢 Configurable hours, minutes, and seconds pickers
  • 🎨 Supports any SwiftUI ShapeStyle background
  • 🧭 Wheel-style interaction (native iOS feel)
  • 🚫 Hides default picker indicators for a minimal design
  • 📱 Presentable via .timePicker(...) modifier
  • 🧾 Fully documented using Apple-style symbol comments

🧱 Requirements

Platform Minimum Version
iOS 17.0
Swift 5.9
Framework SwiftUI

📘 Example Project

This package includes a sample usage preview in #Preview for quick visualization in Xcode’s canvas.
You can also clone the repo and run the demo app target to see the component in action.


🧾 License

This project is licensed under the MIT License — see the LICENSE file for details.


🧑‍💻 Author

Vijay Thakur
iOS Developer • Swift Enthusiast • UI/UX Focused Engineer

  • 💼 LinkedIn
  • 🧑‍💻 GitHub

🏷️ Version History

Version Changes
1.0.0 Initial public release — added TimePicker, .timePicker() modifier, and Apple-style documentation.

“Simplicity is the ultimate sophistication.”
— Leonardo da Vinci

About

A modern, customizable SwiftUI Time Picker component built entirely with SwiftUI — no UIKit overlays or default indicators. It allows users to select hours, minutes, and seconds in a clean, wheel-style layout, perfect for stopwatch, timer, or scheduling features.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Swift 100.0%