Skip to content

Instantly share code, notes, and snippets.

@Cellane
Created January 17, 2014 00:23
Show Gist options
  • Save Cellane/8466166 to your computer and use it in GitHub Desktop.
Save Cellane/8466166 to your computer and use it in GitHub Desktop.
//
// ViewController.m
// CalendarTest
//
// Created by Milan Vít on 17.01.14.
// Copyright (c) 2014 Milan Vít. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
TKCalendarMonthView *calendarMonthView;
}
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic,strong) NSMutableDictionary *dataDictionary;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
calendarMonthView = [[TKCalendarMonthView alloc] initWithSundayAsFirst:NO];
[calendarMonthView setDataSource:self];
[calendarMonthView setDelegate:self];
[[self view] addSubview:calendarMonthView];
}
- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)date
{
NSLog(@"Já si tu jen tak píčuju a borec mi jebnul na %@.", date);
}
- (NSArray *)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate
{
[self generateRandomDataForStartDate:startDate endDate:lastDate];
return self.dataArray;
}
- (void) generateRandomDataForStartDate:(NSDate*)start endDate:(NSDate*)end{
self.dataArray = [NSMutableArray array];
self.dataDictionary = [NSMutableDictionary dictionary];
NSDate *date = start;
while (YES) {
NSDateComponents *dateComponents = [date dateComponentsWithTimeZone:calendarMonthView.timeZone];
if ([dateComponents day] == 3 || [dateComponents day] == 10)
{
[[self dataArray] addObject:@YES];
}
else
{
[[self dataArray] addObject:@NO];
}
[dateComponents setDay:[dateComponents day] + 1];
date = [NSDate dateWithDateComponents:dateComponents];
if ([date compare:end] == NSOrderedDescending)
{
break;
}
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment