Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Examples/Calendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
1D2391395A8710F3E85A8A /* left_arrow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D2391395A8710F3E85A89 /* left_arrow@2x.png */; };
1D2391395A8710F3E85A8C /* right_arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D2391395A8710F3E85A8B /* right_arrow.png */; };
1D2391395A8710F3E85A8E /* right_arrow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D2391395A8710F3E85A8D /* right_arrow@2x.png */; };
96D75AF818FF288500498AD7 /* HCTwoWeekCalendarView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 96D75AF718FF288500498AD7 /* HCTwoWeekCalendarView.xib */; };
96D75AFB18FF31A900498AD7 /* HCPTwoWeekCalendarViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 96D75AFA18FF31A900498AD7 /* HCPTwoWeekCalendarViewController.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -42,6 +44,9 @@
1D2391395A8710F3E85A89 /* left_arrow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "left_arrow@2x.png"; path = "../../Source/resources/left_arrow@2x.png"; sourceTree = "<group>"; };
1D2391395A8710F3E85A8B /* right_arrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = right_arrow.png; path = ../../Source/resources/right_arrow.png; sourceTree = "<group>"; };
1D2391395A8710F3E85A8D /* right_arrow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "right_arrow@2x.png"; path = "../../Source/resources/right_arrow@2x.png"; sourceTree = "<group>"; };
96D75AF718FF288500498AD7 /* HCTwoWeekCalendarView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HCTwoWeekCalendarView.xib; sourceTree = "<group>"; };
96D75AF918FF31A900498AD7 /* HCPTwoWeekCalendarViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HCPTwoWeekCalendarViewController.h; sourceTree = "<group>"; };
96D75AFA18FF31A900498AD7 /* HCPTwoWeekCalendarViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HCPTwoWeekCalendarViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -96,6 +101,9 @@
1D2391395A8710F3E85A66 /* CKViewController.h */,
1D2391395A8710F3E85A64 /* CKAppDelegate.m */,
1D2391395A8710F3E85A63 /* CKAppDelegate.h */,
96D75AF918FF31A900498AD7 /* HCPTwoWeekCalendarViewController.h */,
96D75AFA18FF31A900498AD7 /* HCPTwoWeekCalendarViewController.m */,
96D75AF718FF288500498AD7 /* HCTwoWeekCalendarView.xib */,
1D2391395A8710F3E85A5B /* Supporting Files */,
1D2391395A8710F3E85A86 /* resources */,
);
Expand Down Expand Up @@ -149,6 +157,8 @@
/* Begin PBXProject section */
001D2391395A8710F3E85A45 /* Project object */ = {
isa = PBXProject;
attributes = {
};
buildConfigurationList = 1D2391395A8710F3E85A46 /* Build configuration list for PBXProject "Calendar" */;
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
Expand All @@ -175,6 +185,7 @@
1D2391395A8710F3E85A88 /* left_arrow.png in Resources */,
1D2391395A8710F3E85A8A /* left_arrow@2x.png in Resources */,
1D2391395A8710F3E85A8C /* right_arrow.png in Resources */,
96D75AF818FF288500498AD7 /* HCTwoWeekCalendarView.xib in Resources */,
1D2391395A8710F3E85A8E /* right_arrow@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -190,6 +201,7 @@
1D2391395A8710F3E85A65 /* CKAppDelegate.m in Sources */,
1D2391395A8710F3E85A68 /* CKViewController.m in Sources */,
1D2391395A8710F3E85A85 /* CKCalendarView.m in Sources */,
96D75AFB18FF31A900498AD7 /* HCPTwoWeekCalendarViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -260,6 +272,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Calendar/Calendar-Prefix.pch";
INFOPLIST_FILE = "Calendar/Calendar-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -271,6 +284,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Calendar/Calendar-Prefix.pch";
INFOPLIST_FILE = "Calendar/Calendar-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -295,6 +309,7 @@
1D2391395A8710F3E85A4F /* Debug */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
4 changes: 3 additions & 1 deletion Examples/Calendar/CKAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

self.viewController = [[CKViewController alloc] init];
self.window.rootViewController = self.viewController;
UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navCtrl;
[self.window makeKeyAndVisible];
return YES;
}
Expand Down
130 changes: 95 additions & 35 deletions Examples/Calendar/CKViewController.m
Original file line number Diff line number Diff line change
@@ -1,50 +1,106 @@
#import <CoreGraphics/CoreGraphics.h>
#import "CKViewController.h"
#import "CKCalendarView.h"
#import "HCPTwoWeekCalendarViewController.h"

@interface CKViewController () <CKCalendarDelegate>

@property(nonatomic, weak) CKCalendarView *calendar;
@property(nonatomic, strong) UILabel *dateLabel;
@property(nonatomic, weak) CKCalendarView *nonFlatCalendar;
@property(nonatomic, weak) CKCalendarView *flatCalendar;
@property(nonatomic, strong) UILabel *dateLabelFlat;
@property(nonatomic, strong) UILabel *dateLabelNonFlat;
@property(nonatomic, strong) NSDateFormatter *dateFormatter;
@property(nonatomic, strong) NSDate *minimumDate;
@property(nonatomic, strong) NSArray *disabledDates;
@property(nonatomic, strong) NSDate *disabledDate;
@property(nonatomic, strong) UIScrollView *scrollView;

@end

@implementation CKViewController


- (id)init {
self = [super init];
if (self) {
CKCalendarView *calendar = [[CKCalendarView alloc] initWithStartDay:startMonday];
self.calendar = calendar;
calendar.delegate = self;

self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"dd/MM/yyyy"];
self.minimumDate = [self.dateFormatter dateFromString:@"20/09/2012"];

self.disabledDates = @[
[self.dateFormatter dateFromString:@"05/01/2013"],
[self.dateFormatter dateFromString:@"06/01/2013"],
[self.dateFormatter dateFromString:@"07/01/2013"]
];

calendar.onlyShowCurrentMonth = NO;
calendar.adaptHeightToNumberOfWeeksInMonth = YES;
self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
self.scrollView.scrollEnabled = YES;
self.scrollView.contentSize = CGSizeMake(320, 800);

[self addNonFlatDesignCalendar:CGRectMake(10, 44, 300, 320)];
[self addFlatDesignCalendar:CGRectMake(10, 420, 300, 320)];

[self addButtonToGotoTwoWeekViewController:CGRectMake(10, 720, 200, 22)];

[self.view addSubview:self.scrollView];
}
return self;
}

calendar.frame = CGRectMake(10, 10, 300, 320);
[self.view addSubview:calendar];
- (void)addButtonToGotoTwoWeekViewController:(CGRect)rect
{
UIButton *button = [[UIButton alloc] initWithFrame:rect];

[button setTitle:@"Goto" forState:UIControlStateNormal];
button.backgroundColor = [UIColor redColor];

[button addTarget:self action:@selector(gotoTwoWeekViewClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollView addSubview:button];
}

self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(calendar.frame) + 4, self.view.bounds.size.width, 24)];
[self.view addSubview:self.dateLabel];
- (void)gotoTwoWeekViewClicked:(id)sender
{
UIViewController *viewController = [[HCPTwoWeekCalendarViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
}

self.view.backgroundColor = [UIColor whiteColor];
- (void)addNonFlatDesignCalendar:(CGRect)rect {
CKCalendarView *calendar = [[CKCalendarView alloc] initWithStartDay:startMonday];
self.nonFlatCalendar = calendar;
self.nonFlatCalendar.delegate = self;

self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"dd/MM/yyyy"];
self.minimumDate = [self.dateFormatter dateFromString:@"20/09/2012"];

self.disabledDate = [self.dateFormatter dateFromString:@"05/01/2014"];

calendar.onlyShowCurrentMonth = NO;
calendar.adaptHeightToNumberOfWeeksInMonth = YES;

calendar.frame = rect;
[self.scrollView addSubview:calendar];

self.dateLabelNonFlat = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(calendar.frame), self.view.bounds.size.width, 24)];
[self.scrollView addSubview:self.dateLabelNonFlat];

self.view.backgroundColor = [UIColor whiteColor];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localeDidChange) name:NSCurrentLocaleDidChangeNotification object:nil];
}

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localeDidChange) name:NSCurrentLocaleDidChangeNotification object:nil];
}
return self;
- (void)addFlatDesignCalendar:(CGRect)rect {
CKCalendarView *calendar = [[CKCalendarView alloc] initWithStartDay:startMonday style:CKCalendarStyleFlat];
self.flatCalendar = calendar;
self.flatCalendar.delegate = self;

self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"dd/MM/yyyy"];
self.minimumDate = [self.dateFormatter dateFromString:@"20/09/2012"];

self.disabledDate = [self.dateFormatter dateFromString:@"01/05/2014"],

calendar.onlyShowCurrentMonth = NO;
calendar.adaptHeightToNumberOfWeeksInMonth = YES;

calendar.frame = rect;
[self.scrollView addSubview:calendar];

self.dateLabelFlat = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(calendar.frame), self.view.bounds.size.width, 24)];
[self.scrollView addSubview:self.dateLabelFlat];

self.view.backgroundColor = [UIColor whiteColor];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(localeDidChange) name:NSCurrentLocaleDidChangeNotification object:nil];
}

- (void)dealloc {
Expand Down Expand Up @@ -73,14 +129,13 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
}

- (void)localeDidChange {
[self.calendar setLocale:[NSLocale currentLocale]];
[self.flatCalendar setLocale:[NSLocale currentLocale]];
[self.nonFlatCalendar setLocale:[NSLocale currentLocale]];
}

- (BOOL)dateIsDisabled:(NSDate *)date {
for (NSDate *disabledDate in self.disabledDates) {
if ([disabledDate isEqualToDate:date]) {
return YES;
}
if ([self.disabledDate isEqualToDate:date]) {
return YES;
}
return NO;
}
Expand All @@ -101,15 +156,20 @@ - (BOOL)calendar:(CKCalendarView *)calendar willSelectDate:(NSDate *)date {
}

- (void)calendar:(CKCalendarView *)calendar didSelectDate:(NSDate *)date {
self.dateLabel.text = [self.dateFormatter stringFromDate:date];
if (calendar == self.flatCalendar) {
self.dateLabelFlat.text = [self.dateFormatter stringFromDate:date];
} else {
self.dateLabelNonFlat.text = [self.dateFormatter stringFromDate:date];
}

}

- (BOOL)calendar:(CKCalendarView *)calendar willChangeToMonth:(NSDate *)date {
if ([date laterDate:self.minimumDate] == date) {
self.calendar.backgroundColor = [UIColor blueColor];
calendar.backgroundColor = [UIColor blueColor];
return YES;
} else {
self.calendar.backgroundColor = [UIColor redColor];
calendar.backgroundColor = [UIColor redColor];
return NO;
}
}
Expand Down
13 changes: 13 additions & 0 deletions Examples/Calendar/HCPTwoWeekCalendarViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// HCPTwoWeekCalendarViewController.h
// Calendar
//
// Created by Adam Perry-Pelletier on 4/16/14.
//
//

#import <UIKit/UIKit.h>

@interface HCPTwoWeekCalendarViewController : UIViewController

@end
72 changes: 72 additions & 0 deletions Examples/Calendar/HCPTwoWeekCalendarViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// HCPTwoWeekCalendarViewController.m
// Calendar
//
// Created by Adam Perry-Pelletier on 4/16/14.
//
//

#import "HCPTwoWeekCalendarViewController.h"
#import "CKCalendarView.h"

@interface HCPTwoWeekCalendarViewController ()

@property(nonatomic, strong) NSDateFormatter *dateFormatter;

@end

@implementation HCPTwoWeekCalendarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}


- (void)viewDidLoad
{
[super viewDidLoad];

self.view.backgroundColor = [UIColor whiteColor];
[self addTwoWeekCalendarView:CGRectMake(0,100,320,112)];
}

- (void)addTwoWeekCalendarView:(CGRect)rect {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"HCTwoWeekCalendarView" owner:nil options:nil];
UIView *calendarView = [array lastObject];
calendarView.frame = CGRectMake(0, rect.origin.y, calendarView.frame.size.width, calendarView.frame.size.height);
UIScrollView *innerCalendarView = (UIScrollView *)[calendarView viewWithTag:1];

CKCalendarView *calendar = [[CKCalendarView alloc] initWithStartDay:startMonday
style:CKCalendarStyleFlat
suppressHeader:YES
suppressDayLabels:YES];

self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setDateFormat:@"dd/MM/yyyy"];

calendar.onlyShowCurrentMonth = NO;
calendar.adaptHeightToNumberOfWeeksInMonth = YES;

[innerCalendarView addSubview:calendar];
innerCalendarView.contentSize = calendar.frame.size;

[self.view addSubview:calendarView];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/

@end
Loading