Code Monkey home page Code Monkey logo

bmpickermodal's Introduction

BMPickerModal

BMPickerModal is an iOS drop-in class that displays a UIPicker or a UIDatePicker as modal view or in a popover controller on the iPad. Used to let the user select from a list of data or pick a date without leaving the current screen. Closures allow easy customisation.

Requirements

Built in Swift 3 for iOS 8.0+. All devices supported. can be used in both Swift and in ObjectiveC projects.

You will need Xcode 8 for version 1.1.x and above.

For older projects using Swift 2, use version 1.0.x.

Adding BMPickerModal To Your Project

Cocoapods

CocoaPods is the recommended way to add BMPickerModal to your project. As BMPickerModal is written in Swift, you need to add the use_frameworks! option to your podfile.

pod 'BMPickerModal'

Usage

Import the module to your project.

@import BMPickerModal

Creating

var datePickerModal = BMPickerModal()
datePickerModal?.mode = .datePicker

Available modes:

  • .datePicker - Default
  • .picker

Showing On The iPhone

datePickerModal?.show({ (selectedDate) -> Void in
    let theNewDate = selectedDate as! NSDate
    // Do something with the date here
})

Checking whether the control is visible

let visible: Bool = datePickerModal.isVisible

Showing On The iPad

selection: Closure to be executed when date/data is selected sourceView: View to show from sourceRect: CGRect to align to inViewController: ViewController used to present the modal

datePickerModal?.showInPopover({ (selectedDate) -> Void in
    let theNewDate = selectedDate as! NSDate
    // Do something with the date here
}, sourceView: self.view, sourceRect: cell!.frame, inViewController: self)

Checking whether the control is shown in a popover

let inPopover: Bool = datePickerModal.shownInPopover

Dismissing

datePickerModal?.dismiss()

You can add custom actions to the dismissal event by defining the onDismiss closure.

datePickerModal?.ondismiss()

Customising the DatePicker

Access the UIDatePicker view and cusomise as per the Apple documentation.

datePickerModal?.datePicker.datePickerMode = UIDatePickerMode.date

Customising the Picker

Set the pickerDataSource NSArray property for filling the UIPickerView.

bmpickermodal's People

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.