Home

Awesome

THCalendarDatePicker

Build Status Pod Version Pod Platform Pod License Coverage Status

This control is based on the datepicker-ios control combined with the KNSemiModalViewController.

The original controller was not aware of orientation changes and was missing some customization features that I needed for my project, so I decided to rewrite part of the controller to fit to my needs

Screenshots

iPhone Portrait iPhone Landscape

Installation

CocoaPods

Install with CocoaPods by adding the following to your Podfile:

Objective-C

platform :ios, '8.0'
pod 'THCalendarDatePicker', '~> 1.2.9'

Swift

platform :ios, '8.0'
use_frameworks!
pod 'THCalendarDatePicker', '~> 1.2.9'

Note: We follow http://semver.org for versioning the public API.

Manually

Or copy the THCalendarDatePicker/ directory from this repo into your project. As it is using the KNSemiModalViewController internally as dependency you'll need to add and wire those files as well.

Usage

This is a sample initialization taken from the ExampleProject.

- (IBAction)touchedButton:(id)sender {
    if(!self.datePicker)
        self.datePicker = [THDatePickerViewController datePicker];
    self.datePicker.date = self.curDate;
    self.datePicker.delegate = self;
    [self.datePicker setAllowClearDate:NO];
    [self.datePicker setClearAsToday:YES];
    [self.datePicker setAutoCloseOnSelectDate:YES];
    [self.datePicker setAllowSelectionOfSelectedDate:YES];
    [self.datePicker setDisableHistorySelection:YES];
    [self.datePicker setDisableFutureSelection:NO];
    [self.datePicker setSelectedBackgroundColor:[UIColor colorWithRed:125/255.0 green:208/255.0 blue:0/255.0 alpha:1.0]];
    [self.datePicker setCurrentDateColor:[UIColor colorWithRed:242/255.0 green:121/255.0 blue:53/255.0 alpha:1.0]];

    [self.datePicker setDateHasItemsCallback:^BOOL(NSDate *date) {
     int tmp = (arc4random() % 30)+1;
     if(tmp % 5 == 0)
     return YES;
     return NO;
     }];
    //[self.datePicker slideUpInView:self.view withModalColor:[UIColor lightGrayColor]];
    [self presentSemiViewController:self.datePicker withOptions:@{
                                                                  KNSemiModalOptionKeys.pushParentBack    : @(NO),
                                                                  KNSemiModalOptionKeys.animationDuration : @(1.0),
                                                                  KNSemiModalOptionKeys.shadowOpacity     : @(0.3),
                                                                  }];
}

or how you could do it in Swift

    lazy var datePicker:THDatePickerViewController = {
        var dp = THDatePickerViewController.datePicker()
        dp.delegate = self
        dp.setAllowClearDate(false)
        dp.setClearAsToday(true)
        dp.setAutoCloseOnSelectDate(false)
        dp.setAllowSelectionOfSelectedDate(true)
        dp.setDisableHistorySelection(true)
        dp.setDisableFutureSelection(false)
        //dp.autoCloseCancelDelay = 5.0
        dp.selectedBackgroundColor = UIColor(red: 125/255.0, green: 208/255.0, blue: 0/255.0, alpha: 1.0)
        dp.currentDateColor = UIColor(red: 242/255.0, green: 121/255.0, blue: 53/255.0, alpha: 1.0)
        dp.currentDateColorSelected = UIColor.yellowColor()
        return dp
    }()

    @IBAction func dateButtonTouched(sender: AnyObject) {
        datePicker.date = curDate
        datePicker.setDateHasItemsCallback({(date:NSDate!) -> Bool in
            let tmp = (arc4random() % 30) + 1
            return tmp % 5 == 0
        })
        presentSemiViewController(datePicker, withOptions: [
            KNSemiModalOptionKeys.pushParentBack    : NSNumber(bool: false),
            KNSemiModalOptionKeys.animationDuration : NSNumber(float: 1.0),
            KNSemiModalOptionKeys.shadowOpacity     : NSNumber(float: 0.3)
            ])
    }

Features

V1.2.X

V1.1.X

V1.0.X

Future

Contributions

...are really welcome.

I'm bot using this component anymore in my projects, so the time I can dedicate to its maintainance is really limited.

If you have an idea just fork the library change it and if its useful for others and not affecting the functionality of the library for other users I'll insert it

Contributors

License

Source code of this project is available under the standard MIT license. Please see the license file.