Giter Site home page Giter Site logo

watchkittimepicker's Introduction

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. 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.

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:

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.setup(withInitiallySelectedDate: 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)
    }
    
}

watchkittimepicker's People

Contributors

calda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.