A cool calendar based on Nick Lockwood's iCarousel.
Add this to your Podfile:
pod 'QHCarouselCalendar'
Run a pod install
and import the header where you need it:
#import <QHCarouselCalendar.h>
##Usage
#import <UIKit/UIKit.h>
#import <QHCarouselCalendar.h>
@interface YourViewController : UIViewController <QHCarouselCalendarDataSource, QHCarouselCalendarDelegate>
@property (strong, nonatomic)QHCarouselCalendar *calendar;
@end
self.calendar = [[QHCarouselCalendar alloc] initWithFrame:someFrame]; // someFrame is the frame that you want to give to your calendar. Most likely self.view.frame
self.calendar.dataSource = self;
self.calendar.delegate = self;
[self.view addSubview:self.calendar];
This method is called to get the view for each day. (Think about cellForRowAtIndexPath
from UITableViewController
)
-(UIView*)viewForCalendar:(QHCarouselCalendar*)calendar forDate:(NSDate*)date withSuperviewFrame:(CGRect)frame reusingView:(UIView*)view;
This method allows to flag a specific date as "special". It will have a different look on the day part of the calendar.
-(BOOL)calendar:(QHCarouselCalendar*)calendar isDateSpecial:(NSDate*)date;
-(void)calendar:(QHCarouselCalendar*)calendar didChangeSelectedDate:(NSDate*)date;
-(NSDictionary *)QHCarouselCalendarAttributesForCalendar:(QHCarouselCalendar*)calendar;
To change the calendar's behavior and/or look and feel, you need to implement the following delegate's method:
-(NSDictionary *)QHCarouselCalendarAttributesForCalendar:(QHCarouselCalendar*)calendar{
return @{
QHCarouselCalendarContentCarouselBackgroundColor : [UIColor clearColor],
QHCarouselCalendarDayCarouselBackgroundColor : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2],
QHCarouselCalendarMonthCarouselBackgroundColor : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5],
QHCarouselCalendarYearCarouselBackgroundColor : [UIColor colorWithRed:0 green:0 blue:0 alpha:1],
QHCarouselCalendarYearCarouselHeight : [NSNumber numberWithFloat:0.0f]
... // and any other property that you want to customize (see below)
};
}
The customizable properties are:
The height of the Year part of the calendar. Set it to 0.0f
if you don't want to show years.
The height of the Month part of the calendar. Set it to 0.0f
if you don't want to show months.
The height of the Day part of the calendar.
The background color of the Year part of the calendar.
The background color of the Month part of the calendar.
The background color of the Day part of the calendar.
The background color of the Content part of the calendar.
The color used to hilight today's date on the Day part of the calendar
The color used to hilight the selected date on the Day part of the calendar
The color used to hilight dates marked as "special" on the Day part of the calendar. (see the Data Source)
The border color of today's date on the Day part of the calendar
The border color of the selected date on the Day part of the calendar
The border color of "special" dates on the Day part of the calendar. (see the Data Source)
The font color used for the Years
The font color used for the Months
The font color used for the Days names
The font color used for the Days numbers
The font used for the Years
The font used for the Months
The font used for the Days names
The font used for the Days numbers
The type of the Carousel for the Content part of the calendar.
Please refer to iCarousel's documentation for the possible types.
KNOWN ISSUE: Some carousel types can behave strangely with this calendar.
This class is heavily based on Nick Lockwood's great iCarousel.