โฑ A Time Picker data source for WatchKit that mirrors the behavior of UIDatePicker.
https://github.com/calda/WatchKitTimePicker.git
WatchKitTimePicker is a time picker data source for WatchKit that...
UIDatePicker
WatchKitTimePicker is just one individual .swift file: TimePickerDataSource.swift. You could install it quickly by downloading that file and dragging it in to your Watch App Extension target.
Add github "calda/WatchKitTimePicker" to your Cartfile.
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.
WKInterfaceGroup.WKInterfacePicker objects to the group.@IBOutlet and an @IBAction for each of the pickers.WKInterfaceController subclass:import WatchKit
import Foundation
import WatchKitTimePicker
class 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)
}
}