Skip to content
This repository has been archived by the owner on Sep 8, 2023. It is now read-only.

CapitalGene/objc-CGCalendarView

Repository files navigation

objc-CGCalendarView

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.
  • It uses NSCalendar to support internationalization and localization.

Created for CapitalGene iOS App

Screenshot

Usage

Initalize CGCalendarView

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"];
}

Delegate Methods

- (BOOL)calendarView:(CGCalendarView *)calendarView shouldSelectDate:(NSDate *)date;
- (void)calendarView:(CGCalendarView *)calendarView didSelectDate:(NSDate *)date;

Customization

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

Demo Screenshot

Screenshot

Authors

Chen Liang

Credits

License:

Licensed under the MIT license

About

A Lightweight Horizontal Calendar/Date Picker inspired by Square's TimesSquare

Resources

License

Stars

Watchers

Forks

Packages

No packages published