A Lightweight Horizontal Calendar/Date Picker inspired by Square's TimesSquare https://github.com/square/objc-TimesSquare
-
It uses
UITableView
- Day cells (
UITableViewCell
) will be reused to limit memory footprint.
- Day cells (
-
It uses
NSCalendar
to support internationalization and localization.
Created for CapitalGene iOS App
import CGCalendarView.h
and CGCalendarCell.h
(or your customized UITableViewCell
)
- (void)setupCalendarView
{
// initalize calendarView with frame
self.calendarView = [[CGCalendarView alloc] initWithFrame:CGRectMake(0, 20, 320, CG_CALENDAR_VIEW_HEIGHT)];
// use a **global** NSCalendar
self.calendarView.calendar = calendar;
// Set the background color
self.calendarView.backgroundColor = [UIColor lightGrayColor];
// Set the RowCellClass
self.calendarView.rowCellClass = [CGCalendarCell class];
// The beginning date
self.calendarView.firstDate = [NSDate dateWithTimeIntervalSinceNow: -60 * 60 * 24 * 30];
// The end date
self.calendarView.lastDate = [NSDate dateWithTimeIntervalSinceNow:60 * 60 * 24 * 180];
// didSelectDate delegate
self.calendarView.delegate = self;
// Add the calendarView as a subview
[self.view addSubview:self.calendarView];
// Select Today
self.calendarView.selectedDate = [NSDate date];
// Prepare a dateformatter for displaying the selected
// date
self.DF = [[NSDateFormatter alloc] init];
[self.DF setDateFormat:@"yyyy-MM-dd"];
}
- (BOOL)calendarView:(CGCalendarView *)calendarView shouldSelectDate:(NSDate *)date;
- (void)calendarView:(CGCalendarView *)calendarView didSelectDate:(NSDate *)date;
CGCalendarView doesn't require its rowCellClass
to be a subclass of CGCalendarCell
. Any subclasses of UITableViewCell
with the following properties/methods will work:
- (id)initWithCalendar:(NSCalendar *)calendar reuseIdentifier:(NSString *)reuseIdentifier;
+ (CGFloat)cellHeight;
- (void)setDate: (NSDate*)date
Chen Liang
- Inspired by https://github.com/square/objc-TimesSquare
- UIImage+Additions, Piotr Bernad
- UIView+ViewHelpers, Nathan Mock
Licensed under the MIT license