Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bottom arrow positions, single date selection and auto select date features #15

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions Demo/OCCalendar/OCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ - (void)viewDidAppear:(BOOL)animated {

[calVC setStartDate:sDate];
[calVC setEndDate:eDate];
// [calVC setSelectionColor:[UIColor orangeColor]];
// [calVC setTodayMarkerColor:[UIColor greenColor]];

//Add to the view.
[self.view addSubview:calVC.view];
Expand Down Expand Up @@ -151,6 +153,8 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceive

calVC = [[OCCalendarViewController alloc] initAtPoint:insertPoint inView:self.view arrowPosition:OCArrowPositionRight];
calVC.delegate = self;
// [calVC setSelectionColor:[UIColor orangeColor]];
// [calVC setTodayMarkerColor:[UIColor greenColor]];
[self.view addSubview:calVC.view];

return YES;
Expand Down
28 changes: 25 additions & 3 deletions OCCalendarView/OCCalendarView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@
#import <UIKit/UIKit.h>

typedef enum {
OCArrowPositionLeft = -1,
OCArrowPositionCentered = 0,
OCArrowPositionRight = 1
OCArrowPositionLeft = -1,
OCArrowPositionCentered = 0,
OCArrowPositionRight = 1
} OCArrowPosition;

typedef enum {
OCArrowVerticalPositionTop = 0,
OCArrowVerticalPositionBottom = 1
} OCArrowVerticalPosition;

typedef enum {
OCSelectionSingleDate = 0,
OCSelectionDateRange = 1
} OCSelectionMode;


@class OCSelectionView;
@class OCDaysView;

Expand All @@ -36,13 +47,24 @@ typedef enum {
OCDaysView *daysView;

int arrowPosition;
int arrowVerticalPosition;
int selectionMode;
}

@property (nonatomic, retain) id delegate;

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame;
- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos;
- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos arrowVerticalPosition:(OCArrowVerticalPosition)arrowVerticalPos;
- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos arrowVerticalPosition:(OCArrowVerticalPosition)arrowVerticalPos selectionMode:(OCSelectionMode)selMode;

//Valid Positions: OCArrowPositionLeft, OCArrowPositionCentered, OCArrowPositionRight
- (void)setArrowPosition:(OCArrowPosition)pos;
//Valid Positions: OCArrowVerticalPositionTop, OCArrowVerticalPositionBottom
- (void)setArrowVerticalPosition:(OCArrowVerticalPosition)pos;

- (void) setSelectionColor:(UIColor *)selColor;
- (void) setTodayMarkerColor:(UIColor *)todayColor;

- (NSDate *)getStartDate;
- (NSDate *)getEndDate;
Expand Down
207 changes: 152 additions & 55 deletions OCCalendarView/OCCalendarView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,80 @@

@implementation OCCalendarView

@synthesize delegate;

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame {
return [self initAtPoint:p withFrame:frame arrowPosition:OCArrowPositionCentered];
return [self initAtPoint:p withFrame:frame arrowPosition:OCArrowPositionCentered arrowVerticalPosition:OCArrowVerticalPositionTop selectionMode:OCSelectionDateRange];
}

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos {
//NSLog(@"Arrow Position: %u", arrowPos);

// CGRect frame = CGRectMake(p.x - 390*0.5, p.y - 31.4, 390, 270);
self = [super initWithFrame:frame];
if(self) {
self.backgroundColor = [UIColor clearColor];

calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *dateParts = [calendar components:unitFlags fromDate:[NSDate date]];
currentMonth = [dateParts month];
currentYear = [dateParts year];

arrowPosition = arrowPos;

selected = NO;
startCellX = -1;
startCellY = -1;
endCellX = -1;
endCellY = -1;

hDiff = 43;
vDiff = 30;

selectionView = [[OCSelectionView alloc] initWithFrame:CGRectMake(66, 95, hDiff*7, vDiff*6)];
[self addSubview:selectionView];

daysView = [[OCDaysView alloc] initWithFrame:CGRectMake(65, 98, hDiff*7, vDiff*6)];
[daysView setYear:currentYear];
[daysView setMonth:currentMonth];
[daysView resetRows];
[self addSubview:daysView];
return [self initAtPoint:p withFrame:frame arrowPosition:arrowPos arrowVerticalPosition:OCArrowVerticalPositionTop selectionMode:OCSelectionDateRange];
}

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos arrowVerticalPosition:(OCArrowVerticalPosition)arrowVerticalPos
{
return [self initAtPoint:p withFrame:frame arrowPosition:OCArrowPositionCentered arrowVerticalPosition:arrowVerticalPos selectionMode:OCSelectionDateRange];
}

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos arrowVerticalPosition:(OCArrowVerticalPosition)arrowVerticalPos selectionMode:(OCSelectionMode)selMode
{
//NSLog(@"Arrow Position: %u", arrowPos);

selectionView.frame = CGRectMake(66, 95, hDiff * 7, ([daysView addExtraRow] ? 6 : 5)*vDiff);
// CGRect frame = CGRectMake(p.x - 390*0.5, p.y - 31.4, 390, 270);
self = [super initWithFrame:frame];
if(self)
{
self.backgroundColor = [UIColor clearColor];

calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];

NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *dateParts = [calendar components:unitFlags fromDate:[NSDate date]];
currentMonth = [dateParts month];
currentYear = [dateParts year];

arrowPosition = arrowPos;
arrowVerticalPosition = arrowVerticalPos;


selected = NO;
startCellX = -1;
startCellY = -1;
endCellX = -1;
endCellY = -1;

hDiff = 43;
vDiff = 30;

selectionView = [[OCSelectionView alloc] initWithFrame:CGRectMake(66, 95, hDiff*7, vDiff*6)];
selectionView.selectionMode = selMode;
[self addSubview:selectionView];

daysView = [[OCDaysView alloc] initWithFrame:CGRectMake(65, 98, hDiff*7, vDiff*6)];
[daysView setYear:currentYear];
[daysView setMonth:currentMonth];
[daysView resetRows];
[self addSubview:daysView];

selectionView.frame = CGRectMake(66, 95, hDiff * 7, ([daysView addExtraRow] ? 6 : 5)*vDiff);

//Make the view really small and invisible
CGAffineTransform tranny = CGAffineTransformMakeScale(0.1, 0.1);
self.transform = tranny;
self.alpha = 0.0f;

[self performSelector:@selector(animateIn)];
}
return self;
}

- (void)setDelegate:(id)pDelegate
{
NSString* oldDelegate = delegate;
delegate = [pDelegate retain];
[oldDelegate release];

//Make the view really small and invisible
CGAffineTransform tranny = CGAffineTransformMakeScale(0.1, 0.1);
self.transform = tranny;
self.alpha = 0.0f;

[self performSelector:@selector(animateIn)];
}
return self;
selectionView.delegate = pDelegate;
}

- (void)setFrame:(CGRect)frame {
Expand Down Expand Up @@ -134,6 +159,22 @@ - (void)setArrowPosition:(OCArrowPosition)pos {
arrowPosition = pos;
}

- (void)setArrowVerticalPosition:(OCArrowVerticalPosition)pos
{
arrowVerticalPosition = pos;
}

- (void) setSelectionColor:(UIColor *)selColor
{
selectionView.selectionColor = selColor;
}

- (void) setTodayMarkerColor:(UIColor *)todayColor
{
daysView.todayMarkerColor = todayColor;
}


- (NSDate *)getStartDate {
CGPoint startPoint = [selectionView startPoint];

Expand Down Expand Up @@ -353,6 +394,10 @@ - (void)setEndDate:(NSDate *)eDate {
[daysView setYear:currentYear];
[daysView resetRows];
[daysView setNeedsDisplay];
if (selectionMode == OCSelectionSingleDate)
{
[self setStartDate:[self getEndDate]];
}
}

- (void)drawRect:(CGRect)rect
Expand Down Expand Up @@ -411,26 +456,52 @@ - (void)drawRect:(CGRect)rect
//NSLog(@"Added extra row");
[roundedRectanglePath moveToPoint: CGPointMake(42, 267.42)];
[roundedRectanglePath addCurveToPoint: CGPointMake(52, 278.4) controlPoint1: CGPointMake(42, 273.49) controlPoint2: CGPointMake(46.48, 278.4)];

if (arrowVerticalPosition == OCArrowVerticalPositionBottom)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 278.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 290.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 278.4)];
}

[roundedRectanglePath addLineToPoint: CGPointMake(361.5, 278.4)];
[roundedRectanglePath addCurveToPoint: CGPointMake(371.5, 267.42) controlPoint1: CGPointMake(367.02, 278.4) controlPoint2: CGPointMake(371.5, 273.49)];
[roundedRectanglePath addLineToPoint: CGPointMake(371.5, 53.9)];
[roundedRectanglePath addCurveToPoint: CGPointMake(361.5, 43.9) controlPoint1: CGPointMake(371.5, 48.38) controlPoint2: CGPointMake(367.02, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];

if (arrowVerticalPosition == OCArrowVerticalPositionTop)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];
}

[roundedRectanglePath addLineToPoint: CGPointMake(52, 43.9)];
[roundedRectanglePath addCurveToPoint: CGPointMake(42, 53.9) controlPoint1: CGPointMake(46.48, 43.9) controlPoint2: CGPointMake(42, 48.38)];
[roundedRectanglePath addLineToPoint: CGPointMake(42, 267.42)];
} else {
[roundedRectanglePath moveToPoint: CGPointMake(42, 246.4)];
[roundedRectanglePath addCurveToPoint: CGPointMake(52, 256.4) controlPoint1: CGPointMake(42, 251.92) controlPoint2: CGPointMake(46.48, 256.4)];

if (arrowVerticalPosition == OCArrowVerticalPositionBottom)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 256.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 268.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 256.4)];
}

[roundedRectanglePath addLineToPoint: CGPointMake(361.5, 256.4)];
[roundedRectanglePath addCurveToPoint: CGPointMake(371.5, 246.4) controlPoint1: CGPointMake(367.02, 256.4) controlPoint2: CGPointMake(371.5, 251.92)];
[roundedRectanglePath addLineToPoint: CGPointMake(371.5, 53.9)];
[roundedRectanglePath addCurveToPoint: CGPointMake(361.5, 43.9) controlPoint1: CGPointMake(371.5, 48.38) controlPoint2: CGPointMake(367.02, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];

if (arrowVerticalPosition == OCArrowVerticalPositionTop)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];
}

[roundedRectanglePath addLineToPoint: CGPointMake(52, 43.9)];
[roundedRectanglePath addCurveToPoint: CGPointMake(42, 53.9) controlPoint1: CGPointMake(46.48, 43.9) controlPoint2: CGPointMake(42, 48.38)];
[roundedRectanglePath addLineToPoint: CGPointMake(42, 246.4)];
Expand Down Expand Up @@ -494,26 +565,52 @@ - (void)drawRect:(CGRect)rect
if([daysView addExtraRow]) {
[roundedRectangle2Path moveToPoint: CGPointMake(42, 267.42)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(52, 278.4) controlPoint1: CGPointMake(42, 273.49) controlPoint2: CGPointMake(46.48, 278.4)];

if (arrowVerticalPosition == OCArrowVerticalPositionBottom)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 278.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 290.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 278.4)];
}

[roundedRectangle2Path addLineToPoint: CGPointMake(361.5, 278.4)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(371.5, 267.42) controlPoint1: CGPointMake(367.02, 278.4) controlPoint2: CGPointMake(371.5, 273.49)];
[roundedRectangle2Path addLineToPoint: CGPointMake(371.5, 53.9)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(361.5, 43.9) controlPoint1: CGPointMake(371.5, 48.38) controlPoint2: CGPointMake(367.02, 43.9)];
[roundedRectangle2Path addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectangle2Path addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectangle2Path addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];

if (arrowVerticalPosition == OCArrowVerticalPositionTop)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];
}

[roundedRectangle2Path addLineToPoint: CGPointMake(52, 43.9)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(42, 53.9) controlPoint1: CGPointMake(46.48, 43.9) controlPoint2: CGPointMake(42, 48.38)];
[roundedRectangle2Path addLineToPoint: CGPointMake(42, 267.42)];
} else {
[roundedRectangle2Path moveToPoint: CGPointMake(42, 246.4)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(52, 256.4) controlPoint1: CGPointMake(42, 251.92) controlPoint2: CGPointMake(46.48, 256.4)];

if (arrowVerticalPosition == OCArrowVerticalPositionBottom)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 256.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 268.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 256.4)];
}

[roundedRectangle2Path addLineToPoint: CGPointMake(361.5, 256.4)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(371.5, 246.4) controlPoint1: CGPointMake(367.02, 256.4) controlPoint2: CGPointMake(371.5, 251.92)];
[roundedRectangle2Path addLineToPoint: CGPointMake(371.5, 53.9)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(361.5, 43.9) controlPoint1: CGPointMake(371.5, 48.38) controlPoint2: CGPointMake(367.02, 43.9)];
[roundedRectangle2Path addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectangle2Path addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectangle2Path addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];

if (arrowVerticalPosition == OCArrowVerticalPositionTop)
{
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX+13.5, 43.9)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX, 31.4)];
[roundedRectanglePath addLineToPoint: CGPointMake(arrowPosX-13.5, 43.9)];
}

[roundedRectangle2Path addLineToPoint: CGPointMake(52, 43.9)];
[roundedRectangle2Path addCurveToPoint: CGPointMake(42, 53.9) controlPoint1: CGPointMake(46.48, 43.9) controlPoint2: CGPointMake(42, 48.38)];
[roundedRectangle2Path addLineToPoint: CGPointMake(42, 246.4)];
Expand Down
37 changes: 26 additions & 11 deletions OCCalendarView/OCCalendarViewController.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,41 @@
@end

@interface OCCalendarViewController : UIViewController <UIGestureRecognizerDelegate> {
id <OCCalendarDelegate> delegate;

UILabel *toolTipLabel;
OCCalendarView *calView;

CGPoint insertPoint;
OCArrowPosition arrowPos;

UIView *parentView;
id <OCCalendarDelegate> delegate;

NSDate *startDate;
NSDate *endDate;
UILabel *toolTipLabel;
OCCalendarView *calView;

CGPoint insertPoint;
OCArrowPosition arrowPos;
OCArrowVerticalPosition arrowVerticalPos;
OCSelectionMode selectionMode;

UIView *parentView;
UIView *bgView;
UITapGestureRecognizer *tapG;
NSDate *startDate;
NSDate *endDate;

UIColor *selectionColor;
UIColor *todayMarkerColor;
}

@property (nonatomic, retain) UIColor *selectionColor;
@property (nonatomic, retain) UIColor *todayMarkerColor;
@property (nonatomic, assign) BOOL autoSelectDate;
@property (nonatomic, assign) id <OCCalendarDelegate> delegate;
@property (nonatomic, retain) NSDate *startDate;
@property (nonatomic, retain) NSDate *endDate;

- (id)initAtPoint:(CGPoint)point inView:(UIView *)v;
- (id)initAtPoint:(CGPoint)point inView:(UIView *)v arrowPosition:(OCArrowPosition)ap;
- (id)initAtPoint:(CGPoint)point inView:(UIView *)v arrowPosition:(OCArrowPosition)ap arrowVerticalPosition:(OCArrowVerticalPosition)avp;
- (id)initAtPoint:(CGPoint)point inView:(UIView *)v arrowPosition:(OCArrowPosition)ap arrowVerticalPosition:(OCArrowVerticalPosition)avp selectionMode:(OCSelectionMode)selMode;

- (void) setSelectionColor:(UIColor *)selColor;
- (void) setTodayMarkerColor:(UIColor *)todayColor;

- (void) remove;

@end
Loading