Permalink
Browse files

Working on some more refactoring.

  • Loading branch information...
KyleLeneau committed Sep 30, 2012
1 parent b4994b8 commit 3c79823aae1799c9b737f45ddc080a62600456a5
View
@@ -13,6 +13,13 @@
#define RGB(r, g, b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define RGBA(r, g, b, a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
+static const CGFloat kHeaderHeight = 44.f;
+static const CGFloat kMonthLabelWidth = 240.0f;
+static const CGFloat kMonthLabelHeight = 24.f;
+static const CGFloat kChangeMonthButtonWidth = 46.0f;
+static const CGFloat kChangeMonthButtonHeight = 30.0f;
+
+
@interface iMonthlyCommon : NSObject
@property (nonatomic, readonly) UIImage * leftArrowImage;
@@ -59,8 +59,8 @@ - (void)setCellState:(kDayCellState)state
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
- UIColor * _textColor = nil;
- UIColor * _shadowColor = nil;
+ UIColor * _textColor = [UIColor whiteColor];
+ UIColor * _shadowColor = [UIColor colorWithPatternImage:[[iMonthlyCommon sharedInstance] darkTextPatternImage]];
CGSize _shadowOffset = CGSizeMake(0, 1);
CGRect largerRect = rectByChangingSize(_originalFrame, 1, 1);
@@ -70,22 +70,14 @@ - (void)drawRect:(CGRect)rect
_shadowColor = [UIColor whiteColor];
break;
case kDayCellStateToday:
- _textColor = [UIColor whiteColor];
- _shadowColor = [UIColor colorWithPatternImage:[[iMonthlyCommon sharedInstance] darkTextPatternImage]];
-
[self setFrame:largerRect];
[self drawTodayCellRect:rect];
break;
case kDayCellStateTodaySelected:
- _textColor = [UIColor whiteColor];
- _shadowColor = [UIColor colorWithPatternImage:[[iMonthlyCommon sharedInstance] darkTextPatternImage]];
-
[self setFrame:largerRect];
[self drawTodaySelectedCellRect:rect];
break;
case kDayCellStateSelected:
- _textColor = [UIColor whiteColor];
- _shadowColor = [UIColor colorWithPatternImage:[[iMonthlyCommon sharedInstance] darkTextPatternImage]];
_shadowOffset = CGSizeMake(0, -1);
[self setFrame:largerRect];
@@ -114,9 +106,9 @@ - (void)drawTodaySelectedCellRect:(CGRect)rect
CGContextRef context = UIGraphicsGetCurrentContext();
- UIColor *strokeColor = [UIColor colorWithRed:41.0/255.0 green:54.0/255.0 blue:73.0/255.0 alpha:1.0];
- UIColor *topColor = [UIColor colorWithRed:0/255.0 green:114.0/255.0 blue:226.0/255.0 alpha:1.0];
- UIColor *bottomColor = [UIColor colorWithRed:0/255.0 green:114.0/255.0 blue:226.0/255.0 alpha:1.0];
+ UIColor *strokeColor = RGB(41, 54, 73);
+ UIColor *topColor = RGB(0, 114, 226);
+ UIColor *bottomColor = RGB(0, 114, 226);
drawGlossAndGradient(context, rect, topColor.CGColor, bottomColor.CGColor);
CGContextSetStrokeColorWithColor(context, strokeColor.CGColor);
@@ -130,8 +122,8 @@ - (void)drawTodayCellRect:(CGRect)rect
CGContextRef context = UIGraphicsGetCurrentContext();
- UIColor *topColor = [UIColor colorWithRed:54.0/255.0 green:79.0/255.0 blue:114.0/255.0 alpha:0.8];
- UIColor *bottomColor = [UIColor colorWithRed:250.0/255.0 green:250.0/255.0 blue:250.0/255.0 alpha:0.4];
+ UIColor *topColor = RGBA(54, 79, 114, 0.8);
+ UIColor *bottomColor = RGBA(250, 250, 250, 0.4);
[topColor setFill];
CGContextFillRect(context, rect);
@@ -145,9 +137,9 @@ - (void)drawSelectedCellRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
- UIColor *strokeColor = [UIColor colorWithRed:41.0/255.0 green:54.0/255.0 blue:73.0/255.0 alpha:1.0];
- UIColor *topColor = [UIColor colorWithRed:0/255.0 green:114.0/255.0 blue:226.0/255.0 alpha:1.0];
- UIColor *bottomColor = [UIColor colorWithRed:0/255.0 green:114.0/255.0 blue:226.0/255.0 alpha:1.0];
+ UIColor *strokeColor = RGB(41, 54, 73);
+ UIColor *topColor = RGB(0, 114, 226);
+ UIColor *bottomColor = RGB(0, 114, 226);
drawGlossAndGradient(context, rect, topColor.CGColor, bottomColor.CGColor);
CGContextSetStrokeColorWithColor(context, strokeColor.CGColor);
@@ -136,7 +136,7 @@ - (void)layoutSubviews
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
-
+
UIColor *lightColor = RGBA(154, 158, 167, 0.75);
UIColor *whiteColor = RGB(255, 255, 255);
@@ -0,0 +1,13 @@
+//
+// iMonthlyHeaderView.h
+// iMonthly
+//
+// Created by Kyle LeNeau on 9/29/12.
+// Copyright (c) 2012 LeNeau Software. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface iMonthlyHeaderView : UIView
+
+@end
@@ -0,0 +1,31 @@
+//
+// iMonthlyHeaderView.m
+// iMonthly
+//
+// Created by Kyle LeNeau on 9/29/12.
+// Copyright (c) 2012 LeNeau Software. All rights reserved.
+//
+
+#import "iMonthlyHeaderView.h"
+
+@implementation iMonthlyHeaderView
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ // Initialization code
+ }
+ return self;
+}
+
+/*
+// Only override drawRect: if you perform custom drawing.
+// An empty implementation adversely affects performance during animation.
+- (void)drawRect:(CGRect)rect
+{
+ // Drawing code
+}
+*/
+
+@end
View
@@ -21,17 +21,11 @@ - (void)initView;
@end
-static const CGFloat kHeaderHeight = 44.f;
-static const CGFloat kMonthLabelWidth = 240.0f;
-static const CGFloat kMonthLabelHeight = 24.f;
-static const CGFloat kChangeMonthButtonWidth = 46.0f;
-static const CGFloat kChangeMonthButtonHeight = 30.0f;
-
@implementation iMonthlyView
{
CGRect _headerRect;
CGRect _gridRect;
-
+
UIColor * _headerTextColor;
UIView * _headerView;
@@ -59,7 +53,7 @@ - (void)initView
_headerRect = CGRectMake(0, 0, self.frame.size.width, kHeaderHeight);
_gridRect = CGRectMake(0, kHeaderHeight, self.frame.size.width, self.frame.size.height - kHeaderHeight);
- _headerTextColor = [UIColor colorWithRed:84.0/255.0 green:84.0/255.0 blue:84.0/255.0 alpha:1.0];
+ _headerTextColor = RGB(84, 84, 84);
// Setup Header Views
@@ -205,13 +199,21 @@ - (void)transitionMonthView:(MonthAnimation)animType
- (void)showPreviousMonth
{
+ if (_transitioning) {
+ return;
+ }
+
self.currentMonth = [_currentMonth monthFromMonthOffset:-1];
[_backGridView setCurrentMonth:_currentMonth];
[self transitionMonthView:kRollDown];
}
- (void)showNextMonth
{
+ if (_transitioning) {
+ return;
+ }
+
self.currentMonth = [_currentMonth monthFromMonthOffset:1];
[_backGridView setCurrentMonth:_currentMonth];
[self transitionMonthView:kRollUp];
@@ -222,24 +224,14 @@ - (void)showNextMonth
- (void)layoutSubviews
{
- _previousMonthButton.center = CGPointMake(20, 20);
- _nextMonthButton.center = CGPointMake(300, 20);
-
- _headerTitleLabel.center = CGPointMake(160, 20);
+ _previousMonthButton.center = CGPointMake(20, 20);
+ _nextMonthButton.center = CGPointMake(CGRectGetMaxX(_headerRect) - 20, 20);
+ _headerTitleLabel.center = CGPointMake(CGRectGetMidX(_headerRect), 20);
_gridRect = _frontGridView.frame;
[self setNeedsDisplay];
}
-- (void)drawHeaderView
-{
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- UIColor *topColor = RGB(246, 246, 247);
- UIColor *bottomColor = RGB(204, 204, 209);
- drawLinearGradient(context, _headerRect, topColor.CGColor, bottomColor.CGColor);
-}
-
- (void)drawGridView
{
CGContextRef context = UIGraphicsGetCurrentContext();
@@ -249,20 +241,17 @@ - (void)drawGridView
drawLinearGradient(context, _gridRect, topColor.CGColor, bottomColor.CGColor);
}
-- (void)drawBottomShadowView
-{
- CGContextRef context = UIGraphicsGetCurrentContext();
-
- UIColor *topColor = RGB(246, 246, 247);
- UIColor *bottomColor = RGB(204, 204, 209);
- CGRect shadowRect = CGRectMake(CGRectGetMinX(_gridRect), CGRectGetMaxY(_gridRect), _gridRect.size.width, _gridRect.size.height);
-
- drawLinearGradient(context, shadowRect, topColor.CGColor, bottomColor.CGColor);
-}
+//- (void)drawBottomShadowView
+//{
+// CGContextRef context = UIGraphicsGetCurrentContext();
+//
+// UIColor *topColor = RGBA(246, 246, 247, 1);
+// UIColor *bottomColor = RGBA(204, 204, 209, 0);
+// drawLinearGradient(context, _shadowRect, topColor.CGColor, bottomColor.CGColor);
+//}
- (void)drawRect:(CGRect)rect
{
- [self drawHeaderView]; // Obsolete, replaced by a UIView and Pattern Image for effect
[self drawGridView];
// [self drawBottomShadowView];
}
@@ -0,0 +1,17 @@
+//
+// EmptyViewController.h
+// iMonthly
+//
+// Created by Kyle LeNeau on 9/29/12.
+// Copyright (c) 2012 LeNeau Software. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface EmptyViewController : UIViewController
+
+@end
+
+@interface InnerGlossView : UIView
+
+@end
@@ -0,0 +1,73 @@
+//
+// EmptyViewController.m
+// iMonthly
+//
+// Created by Kyle LeNeau on 9/29/12.
+// Copyright (c) 2012 LeNeau Software. All rights reserved.
+//
+
+#import "EmptyViewController.h"
+#import "iMonthlyCommon.h"
+
+@interface EmptyViewController ()
+
+@end
+
+@implementation EmptyViewController
+
+- (void)viewDidLoad
+{
+ [super viewDidLoad];
+ // Do any additional setup after loading the view.
+}
+
+- (void)loadView
+{
+ InnerGlossView *view = [[InnerGlossView alloc] init];
+ [view setBackgroundColor:RGB(220, 220, 220)];
+ [self setView:view];
+}
+
+@end
+
+
+@implementation InnerGlossView
+
+- (void)drawRect:(CGRect)rect
+{
+ CGContextRef gc = UIGraphicsGetCurrentContext();
+
+ CGRect inner = CGRectMake(40, 40, 240, 240);
+ UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:inner cornerRadius:10];
+// CGPathRef shape = CGPathCreateCopyByStrokingPath(roundedRect.CGPath, NULL, 40, kCGLineCapRound, kCGLineJoinRound, 0);
+ CGPathRef shape = CGPathCreateCopy(roundedRect.CGPath);
+ CGMutablePathRef shapeInverse = CGPathCreateMutableCopy(shape);
+ CGPathAddRect(shapeInverse, NULL, CGRectInfinite);
+
+ CGContextBeginPath(gc);
+ CGContextAddPath(gc, shape);
+ CGContextSetFillColorWithColor(gc, [UIColor redColor].CGColor);
+ CGContextFillPath(gc);
+
+ CGContextSaveGState(gc); {
+ CGContextBeginPath(gc);
+ CGContextAddPath(gc, shape);
+ CGContextClip(gc);
+ CGContextSetShadowWithColor(gc, CGSizeZero, 7, [UIColor colorWithWhite:0 alpha:.25].CGColor);
+ CGContextBeginPath(gc);
+ CGContextAddPath(gc, shapeInverse);
+ CGContextFillPath(gc);
+ } CGContextRestoreGState(gc);
+
+ CGContextSetStrokeColorWithColor(gc, [UIColor colorWithWhite:.75 alpha:1].CGColor);
+ CGContextSetLineWidth(gc, 1);
+ CGContextSetLineJoin(gc, kCGLineCapRound);
+ CGContextBeginPath(gc);
+ CGContextAddPath(gc, shape);
+ CGContextStrokePath(gc);
+
+ CGPathRelease(shape);
+ CGPathRelease(shapeInverse);
+}
+
+@end
@@ -8,6 +8,7 @@
#import "ExampleSelectionViewController.h"
#import "BasicViewController.h"
+#import "EmptyViewController.h"
@implementation ExampleSelectionViewController
@@ -59,7 +60,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
- return 1;
+ return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
@@ -77,6 +78,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
case 0:
cell.textLabel.text = @"Basic iMonthly Example";
break;
+ case 1:
+ cell.textLabel.text = @"Empty View Controller";
+ break;
}
return cell;
@@ -92,6 +96,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
case 0:
example = [[BasicViewController alloc] init];
break;
+ case 1:
+ example = [[EmptyViewController alloc] init];
+ break;
}
if (example != Nil) {
Oops, something went wrong.

0 comments on commit 3c79823

Please sign in to comment.