Giter VIP home page Giter VIP logo

jbcalendardatepicker's Introduction

JBCalendarDatePicker

A replacement for UIDatePicker made for Catalyst.

This is still a work in progress, there are bugs, and although it's written to work with different calendar systems and locales, it's not guaranteed to work correctly with everything!

JBCalendarDatePicker

Installation

To install, add the source to the top of your podfile:

source 'https://github.com/joshbirnholz/JBPodSpecs.git'

Then add this pod to your targets:

pod 'JBCalendarDatePicker'

Use

There are two classes you can use: JBDatePickerViewController and JBCalendarViewController.

They are both similar to UIDatePicker, and their date, minimumDate, maximumDate, calendar, and locale properties can be configured in the same way. Configure them before presenting either of the view controllers.

JBDatePickerViewController also has a datePickerMode property, although UIDatePicker.Mode.countDownTimer is not supported.

JBDatePickerViewController

JBDatePickerViewController

JBDatePickerViewController displays labels showing its represented date and allows the user to use the keyboard to enter a date. When the user clicks on the date portion, the view controller presents its own JBCalendarViewController. You can allow the user to select a date, time, or both, by setting the datePickerMode property.

import JBCalendarDatePicker

class ViewController: UIViewController {

	var datePicker: JBDatePickerViewController!
	
	override func viewDidLoad() {
		super.viewDidLoad()
		
		let datePicker = JBDatePickerViewController()
		view.addSubview(datePicker.view)
		addChild(datePicker)
		datePicker.didMove(toParent: self)
		self.datePicker = datePicker

		// Configure the datePicker's properties
	}
}

Or use it from a storyboard. Drag a Container View onto your storyboard. Change the view controller's class to JBDatePickerViewController. Give the embed segue an identifier, and then capture a reference to it:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
	if segue.identifier == "Embed Date Picker", let destination = segue.destination as? JBDatePickerViewController {
		self.datePicker = destination
		
		// Configure the datePicker's properties
	}
}

JBCalendarViewController

JBCalendarViewController

JBCalendarViewController is just the calendar, without the labels.

The view controller tries to present itself as a popover automatically, so be sure to set the popoverPresentationController's barButtonItem property or the sourceView and sourceRect properties.

@IBOutlet func buttonPressed(_ sender: UIBarButtonItem) {
	let calendarPicker = JBCalendarViewController()
	calendarPicker.popoverPresentationController?.barButtonItem = sender
	
	// Configure the calendar's properties
	
	present(calendarPicker, animated: true, completion: nil)
}

There is also a JBCalendarViewControllerDelegate protocol.

public protocol JBCalendarViewControllerDelegate: class {
	func calendarViewControllerDateChanged(_ calendarViewController: JBCalendarViewController)
	func calendarViewControllerWillDismiss(_ calendarViewController: JBCalendarViewController)
	func calendarViewControllerDidDismiss(_ calendarViewController: JBCalendarViewController)
}

jbcalendardatepicker's People

Contributors

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