Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calda/WatchKitTimePicker
⏱ A Time Picker data source for WatchKit that mirrors the behavior of UIDatePicker.
https://github.com/calda/WatchKitTimePicker
picker swift time uidatepicker watchkit watchos
Last synced: 3 months ago
JSON representation
⏱ A Time Picker data source for WatchKit that mirrors the behavior of UIDatePicker.
- Host: GitHub
- URL: https://github.com/calda/WatchKitTimePicker
- Owner: calda
- License: mit
- Created: 2018-11-05T17:40:50.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-22T23:17:45.000Z (about 5 years ago)
- Last Synced: 2024-06-30T16:54:04.587Z (4 months ago)
- Topics: picker, swift, time, uidatepicker, watchkit, watchos
- Language: Swift
- Homepage:
- Size: 995 KB
- Stars: 41
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-apple-watch - WatchKitTimePicker
README
# WatchKitTimePicker
**WatchKitTimePicker** is a time picker data source for WatchKit that...
- Mirrors the behavior of UIKit's `UIDatePicker`
- Automatically uses either 12-hour or 24-hour time, depending on the user's current Locale.
- Supports watchOS 2.0+
## Demo
## Installation
#### Manual Installation:
**WatchKitTimePicker** is just one individual .swift file: [`TimePickerDataSource.swift`](https://github.com/calda/WatchKitTimePicker/blob/master/WatchKitTimePicker/TimePickerDataSource.swift). You could install it quickly by downloading that file and dragging it in to your Watch App Extension target.
#### [Carthage](https://github.com/Carthage/Carthage):
Add `github "calda/WatchKitTimePicker"` to your Cartfile.
## Usage
Unlike with iOS view-layer libraries, you can't just distribute and use a `UIView` or `WKInterfaceObject` subclass. Interface elements have to be set up using Interface Builder.
**WatchKitTimePicker** is a data source that controls and manages a group of `WKInterfacePicker` objects.
### Interface Builder:
- Create a horizontal `WKInterfaceGroup`.
- Add three `WKInterfacePicker` objects to the group.
- Connect and `@IBOutlet` and an `@IBAction` for each of the pickers.### Your `WKInterfaceController` subclass:
```Swift
import WatchKit
import Foundation
import WatchKitTimePickerclass InterfaceController: WKInterfaceController {
var timePickerDataSource: TimePickerDataSource!
@IBOutlet weak var hourTimePicker: WKInterfacePicker!
@IBOutlet weak var minuteTimePicker: WKInterfacePicker!
@IBOutlet weak var amPmTimePicker: WKInterfacePicker!
override func awake(withContext context: Any?) {
timePickerDataSource = TimePickerDataSource(
hoursPicker: hourTimePicker,
minutesPicker: minuteTimePicker,
amPmPicker: amPmTimePicker,
interval: .fiveMinutes) // supports .minute, .fiveMinutes, .fifteenMinutes, and .halfHour
timePickerDataSource.selectedTimeDidUpdate = { selectedTime in
// ...
}
timePickerDataSource.updateDate(to: Date())
}
@IBAction func hourPickerDidUpdate(_ index: Int) {
timePickerDataSource.hourPickerUpdated(to: index)
}
@IBAction func minutePickerDidUpdate(_ index: Int) {
timePickerDataSource.minutePickerUpdated(to: index)
}
@IBAction func amPmPickerDidUpdate(_ index: Int) {
timePickerDataSource.amPmPickerUpdated(to: index)
}
}```