Code Monkey home page Code Monkey logo

droidtimeselection's Introduction

DroidTimeSelection

Version License Platform

Coming Soon:

  • Full Storyboard support.
  • Add Swift Package manager support.
  • Add Carthage support.
  • Add smoother animations for mode transitions.
  • Add the color-invert effect similar to the original android selector.

Overview

As someone who used Android for a long time, I found I really miss selecting time using the Android method. So, I brought it to iOS.

DroidTimeSelection is, well, the Android-way of selecting time.

It allows using the Clock selector way of picking time:

Or the picker (iOS-way) of picking time:

Installation

DroidTimeSelection is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'DroidTimeSelection'

Usage

Programmatic

First of all, make sure to import "DroidTimeSelection" in all places you intend to use this.

Menu with both (both methods)

Create an instance of the menu:

let menuMethod = DroidTimeSelection()

You can also modify the configuration for the menu

menuMethod.config.timeFormat = .twelve
menuMethod.config.okButtonColor = .blue
//etc

You can set an already existing time (either Time format or hours, minutes, am/pm):

menuMethod.set(time: existingTime)
//or
menuMethod.set(hour: 0, minutes: 0, am: false)

To listen for menu events, access the following closures:

menuMethod.onOkTapped = { [weak self] in
    let value = menuMethod.value //the time selected
    //Your code here.
}

menuMethod.onCancelTapped = { [weak self] in
    //Your code here.
}

menuMethod.onSelectionChanged = { [weak self] value in
    //Your code here
}

Clock Selection

Create an instance of the menu:

let clockMethod = DroidClockSelector(frame: .zero)

Add it somewhere via absolute position or auto layout.

You can also modify the configuration for the menu

clockMethod.config.timeFormat = .twelve
clockMethod.config.timeColor = .blue
//etc

You can set an already existing time (either Time format or hours, minutes, am/pm):

clockMethod.set(time: existingTime)
//or
clockMethod.set(hour: 0, minutes: 0, am: false)

To listen for menu events, access the following closures:

clockMethod.onSelectionChanged = { [weak self] value in
    //Your code here
}

Picker Selection

Create an instance of the menu:

let pickerMethod = DroidPickerSelector(frame: .zero)

Add it somewhere via absolute position or auto layout.

You can also modify the configuration for the menu

pickerMethod.config.timeFormat = .twelve
pickerMethod.config.timeColor = .blue
//etc

You can set an already existing time (either Time format or hours, minutes, am/pm):

pickerMethod.set(time: existingTime)
//or
pickerMethod.set(hour: 0, minutes: 0, am: false)

To listen for menu events, access the following closures:

pickerMethod.onSelectionChanged = { [weak self] value in
    //Your code here
}

Storyboard

Coming Soon.

Customization

You can customize the following aspects:

Clock Selector Configuration

largeSelectionFont: UIFont (default: .systemFont(ofSize: 18))
smallSelectionFont: UIFont (default: .systemFont(ofSize: 14))
largeSelectionColor: UIColor (default: .white)
smallSelectionColor: UIColor (default: .gray)
timeFont: UIFont (default: .systemFont(ofSize: 60))
amPmFont: UIFont (default: .systemFont(ofSize: 30))
timeColor: UIColor (default: .gray)
highlightedTimeColor: UIColor (default: .white)
selectionIndicatorColor: UIColor (default: .systemTeal)
selectionBackgroundColor: UIColor (default: .clear)
timeFormat: DroidTimeFormat (default: .twentyFour. Either .twentyFour or .twelve)

Picker Selector Configuration

cancelButtonColor: UIColor (default: .white)
okButtonColor: UIColor (default: .white)
modeButtonColor: UIColor (default: .white)
okButtonText: String (default: "OK")
cancelButtonText: String (default: "CANCEL")
timeFormat: DroidTimeFormat (default: .twentyFour. Either .twentyFour or .twelve)

Menu Selector (both methods) Configuration

titleFont: UIFont (default: .systemFont(ofSize: 26, weight: .bold))
titleColor: UIColor (default: .white)
pickerColor: UIColor (default: .white)
titleText: String (default: "Set Time")
timeFormat: DroidTimeFormat (default: .twentyFour)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

  • iOS 11 or above.

Author

DDraiman1990, [email protected] a.k.a Nexxmark Studio.

License

DroidTimeSelection is available under the MIT license. See the LICENSE file for more info.

Attributions

Library's logo

The original icon was mixed from an icon made by Those Icons and Freepik both from www.flaticon.com.

droidtimeselection's People

Contributors

ddraiman1990 avatar

Watchers

 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.