GithubHelp home page GithubHelp logo

thcalendardatepicker's Introduction

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

  • Fixed issue #28
  • Fixed issue #30
  • Fixed issue #69
  • Fixed issue #71
  • Pull request #40
  • Pull request #41
  • Pull request #53
  • Pull request #70

V1.1.X

  • Fixed issue #29
  • Fixed issue #27

V1.0.X

  • Fixed issue #23
  • Fixed issue #22
  • Pull request #21, #20
  • Fixed issues #18, #17, #16, #15
  • Pull request #13
  • iOS8 deprecation warnings removed
  • Fixed issues #12, #11, #7, #5
  • Bugfix (Now it's taking the default starting day for the locale; but not the custom setting "Week starts on")
  • Configurable if it should show future entries
  • Select a Date from Calendar
  • Awareness of the setting 4 the first weekday
  • Configurable Colors
  • Configurable if it should be allowed to clear the selection
  • Configurable if it should close on selection or not

Future

  • reduce size of control if "hasItemCallback" is not used/disabled

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.

thcalendardatepicker's People

Contributors

adambco avatar bryant1410 avatar erwannrobin avatar hons82 avatar mkoppanen avatar moi68 avatar mzp avatar oggerschummer avatar powfulhong avatar vladborovtsov avatar wafflecohn avatar wesgood avatar wj2061 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thcalendardatepicker's Issues

How to select a year

Hi, i want to use this calendar also for birthdays, theres a way to select a specific year without having to pass thoroug all the months?

why ok button disabled?

[self.datePicker setDisableHistorySelection:NO];
I want to select History date,but when I selected the date the ok button could not be clicked.

Multiple date picker and Start date, End date feature

Hello,

I'm using your date picker, it works great. But do you have a way to implement multiple date pickers with Start Date and End Date feature, the picker for start date and end date should be limited by each others

Thanks.

delegate method for when closing by touching outside calendar?

Hi. I can't find a way to track when a user brings up the calendar, then dismisses by touching outside the calendar. It doesn't call datePickerCancelPressed. Maybe I'm missing something. Any help is appreciated.

Love this simple calendar control. Fits my app well.

Take the date in the past

Is it possible to pick a date in the past?
e.g today is 2015-11-10
I would like to pick a date at 2015-11-05

today button

can you please add today button to the picker
thanks in advance

Calendar dates are localised

Though this might be desirable in some scenarios, having each day set relative to the user's timezone, rather than relative to UTC, means that it is difficult to compare dates across different devices, or on a server.

It would be very useful to add a setting that sets each day's date relative to UTC instead. (This can be achieved by adding the line:

// setDisplayedMonth:
[df setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];

After line 324 in THDatePickerViewController.m.)

Disable past date selection

Could you add a function for disallowing selection of the date in the past. And so the calendar also doesn't allows to go to previous month on opening if the option is enabled.
thanks in advance

Any chance of adding an option for multiple day selection?

I have a requirement on my project to select multiple days, do you think this could be useful for other users too? I will most likely modify the component to adapt to my needs, so I was wondering if this would be a pull request you would accept.

Thanks
screen shot 2015-09-04 at 16 42 23

iOS7 crash because of iOS8 api

In THDateDay.m line 35,40
In THDatePickerViewController.m line 122,466

  • (UIImage *)imageNamed:(NSString *)name inBundle:(NSBundle *)bundle compatibleWithTraitCollection:(UITraitCollection *)traitCollection NS_AVAILABLE_IOS(8_0);

Dates in history get greyed out

I was checking the example project without doing anything to it and noticed the issue.
If you select some date, then change the month and go back all the dates before your selected date are greyed out.

I hope my explanation is clear enough.
Great looking picker btw 👍

Edit: found that this solves the issue but you can't actually select any date before current day.
[self.datePicker setDisableHistorySelection:NO];

Unless you turn on this:
[self.datePicker setDisableHistorySelection:NO];
But that has also issue that when you select a day that is in greyed out because it's in another month you don't get selection.

Edit 2:
And everything except the autoselection is actually fixed here ipodishima@284c337

Dismiss picker by clicking outside it

KNSemiModalViewController seems to implement this already but it's not working here. Trying to check what's the problem, but letting everyone know if someone know what's going on.

Current date color issue

When I click on a different day and go to the next month, I hit back to the current month and the current day color is not set.

Select number of days selected from current date

Would be great if the calendar can have a new feature to only allow selection of up to n days(example 30 days) from current date. I only see disable future selection, which upon toggled every upcoming days can't be selected

Warnings

Hi, i've got warnings in the pod, how can i ignore them or can you fix them?
screen shot 2015-09-17 at 23 46 52

How To add Date

Thanks for this pretty Control i appreciate your efforts
can you advice if i have dates like
"2015-09-10",
"2015-09-12",
"2015-09-13"
and need to use
[self.datePicker setDateHasItemsCallback:^BOOL(NSDate *date
how to do
Regards

Come to today by a single click?

In my app I am using this calendar.I want 2 functionality’s
1.After going to some other month by clicking next/previous button,is there any way to come back to the current month view by a single click
2.I am adding some events dynamically in the calendar,how should I add dots at the same time of adding event for a particular date.

closeOnSelectDate not working properly

Thought I'd open new issue for this one.

So the issue is that whenever the date is in other than current mont (date is grey) and you try to select that date the picker doesn't close. And obviously that date can't be selected.

I'll attach couple screenshots to show this. Current date is december 9th and user clicks on january 9th.

current date december 9th
try to select january 9th

Title for calendar picker

The calendar picker is great, but I think that something is missing : it could be interesting to have the possibility to add a title to the calendar, to know what we are selecting date for.

Two dates become selected

When you select a date outside the current month, the calendar selects the new day and switches to the new month, however if you try to select a different day both dates become selected.. the datePickerDonePressed method gives the correct selected date it just looks bad. Happens if you select a date in the month before or after while still in a given month.
screen shot 2015-03-02 at 8 03 31 pm

startDate and stopDate range

I'm developing an app in which the user is supposed to select a future date. It would be really nice if there was a property (e.g. NSDate *startdate) on the calendar that made sure no dates earlier than that are displayed, and a property (e.g. NSDate *stopdate) that made sure no dates after that are displayed.

Slow animation

When i run following code on a button press calendar takes 4 to 5 second to show up. How can we speed it up?

if(!self.datePicker)
self.datePicker = [THDatePickerViewController datePicker];
self.datePicker.date = deadlineDate;
self.datePicker.delegate = self;
[self.datePicker setAllowClearDate:NO];
[self.datePicker setClearAsToday:YES];
[self.datePicker setAutoCloseOnSelectDate:NO];
[self.datePicker setAllowSelectionOfSelectedDate:YES];
[self.datePicker setDisableYearSwitch:YES];
//[self.datePicker setDisableFutureSelection:NO];
//[self.datePicker setDaysInHistorySelection:1];
[self.datePicker setDisableFutureSelection:NO];
//[self.datePicker setDateTimeZoneWithName:@"UTC"];
//[self.datePicker setAutoCloseCancelDelay:5.0];
[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 setCurrentDateColorSelected:[UIColor yellowColor]];

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

Weeks start with Sunday

It would be nice to be able to make the calendar appear beginning with Sunday instead of Monday

Lack of documentation for -setDateHasItemsCallback:

Hey, I was hoping you could provide more documentation as to what this part of your initialization does:

[self.datePicker setDateHasItemsCallback:^BOOL(NSDate *date) {
int tmp = (arc4random() % 30)+1;
if(tmp % 5 == 0)
return YES;
return NO;
}];

__NSCFCalendar components:fromDate

What is going on after I updated to 1.2.5?

*** -[__NSCFCalendar components:fromDate:]: date cannot be nil
Future exception.

Thank You

Add a method to get calender date components

At the moment, the THDatePickerViewController has a method to get the date selected by the user, but it would actually be more accurate to get the date components, as a NSDateComponents object. (In fact, this would be preferable to the solution discussed in #30).

Could not load NIB in bundle: with name 'THDatePickerViewController'

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/.../Library/Application Support/iPhone Simulator/7.1/Applications/80863DB6-3C07-415C-A90A-BFB17297C2A5/....app> (loaded)' with name 'THDatePickerViewController''

The problem is that when you install it with pods, the file "THDatePickerViewController.xib" is not here. It should be distributed via pod.

Please, check your .podspec has line like
s.resources = 'Classes/__/
.{xib,png}'

pushParentBack error

On the line: KNSemiModalOptionKeys.pushParentBack : NSNumber(bool: false), I am getting the error:

Cannot convert value of type 'Unmanaged!' to expected dictionary key type 'NSObject'

Ambiguous reference to member 'KNSemiModalOptionKeys'

presentSemiViewController(datePicker, withOptions: [
            KNSemiModalOptionKeys.pushParentBack    : NSNumber(bool: false),
            KNSemiModalOptionKeys.animationDuration : NSNumber(float: 1.0),
            KNSemiModalOptionKeys.shadowOpacity     : NSNumber(float: 0.3)
            ])

The first line brings about the error

swift 2.0 issue

Hi,

I'm trying to compile the project will your sample,
but I've been getting this issue:
Type 'KNSemiModalOption' does not conform to protocol 'Hashable'

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.