Skip to content

Commit

Permalink
Proper definitions of arrow positions.
Browse files Browse the repository at this point in the history
Plus the ability to set the position when initializing the object using the enum.
  • Loading branch information
markrickert committed Apr 5, 2012
1 parent 76ef2e9 commit c859dac
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Demo/OCCalendar/OCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ - (void)viewDidAppear:(BOOL)animated {


//Here's where the magic happens
calVC = [[OCCalendarViewController alloc] initAtPoint:CGPointMake(150, 50) inView:self.view];
calVC = [[OCCalendarViewController alloc] initAtPoint:CGPointMake(150, 50) inView:self.view arrowPosition:OCArrowPositionCentered];
calVC.delegate = self;
[self.view addSubview:calVC.view];
}
Expand Down
13 changes: 9 additions & 4 deletions OCCalendarView/OCCalendarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

#import <UIKit/UIKit.h>

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

@class OCSelectionView;
@class OCDaysView;

Expand All @@ -17,7 +23,6 @@
int currentMonth;
int currentYear;


BOOL selected;
int startCellX;
int startCellY;
Expand All @@ -34,10 +39,10 @@
}

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame;
- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(int)arrowPosition;
- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(OCArrowPosition)arrowPos;

//-1 means it's in the upper-left, 0 means it's in the middle, and 1 means it's in the upper-right.
- (void)setArrowPosition:(int)pos;
//Valid Positions: OCArrowPositionLeft, OCArrowPositionCentered, OCArrowPositionRight
- (void)setArrowPosition:(OCArrowPosition)pos;

- (NSDate *)getStartDate;
- (NSDate *)getEndDate;
Expand Down
14 changes: 9 additions & 5 deletions OCCalendarView/OCCalendarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
@implementation OCCalendarView

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

- (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(int)arrowPosition {
- (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) {
Expand All @@ -30,6 +32,8 @@ - (id)initAtPoint:(CGPoint)p withFrame:(CGRect)frame arrowPosition:(int)arrowPos
currentMonth = [dateParts month];
currentYear = [dateParts year];

arrowPosition = arrowPos;

selected = NO;
startCellX = -1;
startCellY = -1;
Expand Down Expand Up @@ -122,7 +126,7 @@ - (void)resetViews {
[UIView commitAnimations];
}

- (void)setArrowPosition:(int)pos {
- (void)setArrowPosition:(OCArrowPosition)pos {
arrowPosition = pos;
}

Expand Down Expand Up @@ -262,9 +266,9 @@ - (void)drawRect:(CGRect)rect

float arrowPosX = 208;

if(arrowPosition == -1) {
if(arrowPosition == OCArrowPositionLeft) {
arrowPosX = 67;
} else if(arrowPosition == 1) {
} else if(arrowPosition == OCArrowPositionRight) {
arrowPosX = 346;
}

Expand Down
19 changes: 11 additions & 8 deletions OCCalendarView/OCCalendarViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import <UIKit/UIKit.h>
#import "OCCalendarView.h"

@class OCCalendarView;

Expand All @@ -17,18 +18,20 @@
@end

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

UILabel *toolTipLabel;
OCCalendarView *calView;

CGPoint insertPoint;

UIView *parentView;
id <OCCalendarDelegate> delegate;

UILabel *toolTipLabel;
OCCalendarView *calView;

CGPoint insertPoint;
OCArrowPosition arrowPos;

UIView *parentView;
}

@property (nonatomic, assign) id <OCCalendarDelegate> delegate;

- (id)initAtPoint:(CGPoint)point inView:(UIView *)v;
- (id)initAtPoint:(CGPoint)point inView:(UIView *)v arrowPosition:(OCArrowPosition)ap;

@end
21 changes: 12 additions & 9 deletions OCCalendarView/OCCalendarViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

#import "OCCalendarViewController.h"
#import "OCCalendarView.h"
#import <QuartzCore/QuartzCore.h>

@interface OCCalendarViewController ()
Expand All @@ -17,13 +16,18 @@ @interface OCCalendarViewController ()
@implementation OCCalendarViewController
@synthesize delegate;

- (id)initAtPoint:(CGPoint)point inView:(UIView *)v arrowPosition:(OCArrowPosition)ap {
self = [super initWithNibName:nil bundle:nil];
if(self) {
insertPoint = point;
parentView = v;
arrowPos = ap;
}
return self;
}

- (id)initAtPoint:(CGPoint)point inView:(UIView *)v {
self = [super initWithNibName:nil bundle:nil];
if(self) {
insertPoint = point;
parentView = v;
}
return self;
return [self initAtPoint:point inView:v arrowPosition:OCArrowPositionCentered];
}

- (void)loadView {
Expand All @@ -34,7 +38,6 @@ - (void)loadView {
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];


//this view sits behind the calendar and receives touches. It tells the calendar view to disappear when tapped.
UIView *bgView = [[UIView alloc] initWithFrame:self.view.frame];
bgView.backgroundColor = [UIColor clearColor];
Expand All @@ -48,7 +51,7 @@ - (void)viewDidAppear:(BOOL)animated {
int width = 390;
int height = 300;

calView = [[OCCalendarView alloc] initAtPoint:insertPoint withFrame:CGRectMake(insertPoint.x - width*0.5, insertPoint.y - 31.4, width, height)];
calView = [[OCCalendarView alloc] initAtPoint:insertPoint withFrame:CGRectMake(insertPoint.x - width*0.5, insertPoint.y - 31.4, width, height) arrowPosition:arrowPos];
[self.view addSubview:[calView autorelease]];
}

Expand Down

0 comments on commit c859dac

Please sign in to comment.