DurationPicker is an iOS library that provides a customizable control for inputting time values ranging between 0 and 24 hours. It serves as a drop-in replacement of UIDatePicker with countDownTimer mode with additional functionality for time input.
- Styled to match
UIDatePicker
withcountDownTimer
mode - Multiple modes for selection of hours, minutes, and/or seconds
- Option to specify intervals for hour, minute, and/or seconds
- Support for minimum and maximum durations
- Localization in 26+ languages
- Built-in support for accessibility and VoiceOver
To use DurationPicker, simply create an instance of DurationPicker
and add it to your view hierarchy. You can customize your picker using the following properties:
pickerMode
: The mode of the picker, determines whether the duration picker allows selection of hours, minutes, and/or seconds{hour|minute|second}Interval
: The intervals at which the duration picker should display{minimum|maximum}Duration
: The minimum/maximum duration that the picker can show
The code below will produce the following duration picker.
import DurationPicker
let picker = DurationPicker()
addSubview(picker)
picker.pickerMode = .minuteSecond
picker.minuteInterval = 5
picker.secondInterval = 30
picker.minimumDuration = (15 * 60) // 15 minutes
picker.maximumDuration = (45 * 60) + 30 // 45 minutes, 30 seconds
The selected duration can also be set programmatically through the duration
property.
picker.duration = (30 * 60) + 30 // 30 minutes, 30 seconds
You can react to changes in the duration's picker value using UIActions.
let action = UIAction { [weak picker] _ in
guard let picker else { return }
print(picker.duration) // 1830
},
for: .primaryAction)
picker.addAction(action)
To see DurationPicker
in action, clone the repository and open the DurationPickerDemo
project.
In addition to demonstrating the features of DurationPicker
, the demo app serves as an example of how a DurationPicker
can be used in a modern collection view.
Full documentation available on Github Pages.
DurationPicker is available through Swift PM. To install it, simply add the package as a dependency in Package.swift
:
dependencies: [
.package(url: "https://github.com/mac-gallagher/DurationPicker.git", from: "1.0.0"),
]
Download and drop the Sources
directory into your project.
- iOS 15.0+
- XCode 15.0+
- Swift 5.9+
DurationPicker is available under the MIT license. See LICENSE for more information.
Contributions are welcome! Fork the repo, make your changes, and submit a pull request.