Skip to content

Commit

Permalink
Minor refactoring & bug fixes #28
Browse files Browse the repository at this point in the history
* CircleView -> AuxiliaryView with multiple shapes
* Circle geometry on DayView
* Types globalisation
* Refactoring
  • Loading branch information
mozharovsky committed Apr 5, 2015
1 parent 413c044 commit 36712c6
Show file tree
Hide file tree
Showing 22 changed files with 638 additions and 412 deletions.
100 changes: 69 additions & 31 deletions CVCalendar Demo/CVCalendar Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@
55E122591A588CC50013B002 /* CVCalendarViewAppearanceDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E122491A588CC50013B002 /* CVCalendarViewAppearanceDelegate.swift */; };
55E1225A1A588CC50013B002 /* CVCalendarViewDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E1224A1A588CC50013B002 /* CVCalendarViewDelegate.swift */; };
55E1225B1A588CC50013B002 /* CVCalendarWeekView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E1224B1A588CC50013B002 /* CVCalendarWeekView.swift */; };
55E1225C1A588CC50013B002 /* CVCircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E1224C1A588CC50013B002 /* CVCircleView.swift */; };
55E1225D1A588CC50013B002 /* CVDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55E1224D1A588CC50013B002 /* CVDate.swift */; };
8F1080B61AB89B9700D9FAC6 /* CVCalendarTouchController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1080B51AB89B9700D9FAC6 /* CVCalendarTouchController.swift */; };
8F1080B81AB89CCB00D9FAC6 /* CVSelectionType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1080B71AB89CCB00D9FAC6 /* CVSelectionType.swift */; };
8F1080BA1AB89CD400D9FAC6 /* CVRange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1080B91AB89CD400D9FAC6 /* CVRange.swift */; };
8F1080D31AB8C84600D9FAC6 /* CVSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F1080D21AB8C84600D9FAC6 /* CVSet.swift */; };
8F827D071ABF682B005294B1 /* CVAuxiliaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F827D061ABF682B005294B1 /* CVAuxiliaryView.swift */; };
8FDB51EF1AC09E0200F7F7AC /* CVShape.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FDB51EE1AC09E0200F7F7AC /* CVShape.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -78,12 +79,13 @@
55E122491A588CC50013B002 /* CVCalendarViewAppearanceDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVCalendarViewAppearanceDelegate.swift; sourceTree = "<group>"; };
55E1224A1A588CC50013B002 /* CVCalendarViewDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVCalendarViewDelegate.swift; sourceTree = "<group>"; };
55E1224B1A588CC50013B002 /* CVCalendarWeekView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVCalendarWeekView.swift; sourceTree = "<group>"; };
55E1224C1A588CC50013B002 /* CVCircleView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVCircleView.swift; sourceTree = "<group>"; };
55E1224D1A588CC50013B002 /* CVDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVDate.swift; sourceTree = "<group>"; };
8F1080B51AB89B9700D9FAC6 /* CVCalendarTouchController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVCalendarTouchController.swift; sourceTree = "<group>"; };
8F1080B71AB89CCB00D9FAC6 /* CVSelectionType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVSelectionType.swift; sourceTree = "<group>"; };
8F1080B91AB89CD400D9FAC6 /* CVRange.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVRange.swift; sourceTree = "<group>"; };
8F1080D21AB8C84600D9FAC6 /* CVSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVSet.swift; sourceTree = "<group>"; };
8F827D061ABF682B005294B1 /* CVAuxiliaryView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVAuxiliaryView.swift; sourceTree = "<group>"; };
8FDB51EE1AC09E0200F7F7AC /* CVShape.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CVShape.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -164,56 +166,89 @@
55E1223D1A588CC50013B002 /* CVCalendar */ = {
isa = PBXGroup;
children = (
55E122451A588CC50013B002 /* CVCalendarView.swift */,
553524691A794AC400EE9FDE /* CVCalendarContentDelegate.swift */,
5534574D1A75114B00370955 /* CVCalendarWeekContentRecovery.swift */,
55E122411A588CC50013B002 /* CVCalendarManager.swift */,
55E122421A588CC50013B002 /* CVCalendarMenuView.swift */,
55E122441A588CC50013B002 /* CVCalendarRenderer.swift */,
55E122461A588CC50013B002 /* CVCalendarViewAnimator.swift */,
55E122471A588CC50013B002 /* CVCalendarViewAnimatorDelegate.swift */,
8F61EDD51AD1A60F00F7F8B6 /* Main Views */,
8F61EDD71AD1A67900F7F8B6 /* Unit Views */,
8F61EDD31AD1A5CD00F7F8B6 /* Controllers */,
8F61EDD61AD1A65A00F7F8B6 /* Content Views */,
8F61EDD21AD1A5C800F7F8B6 /* Models */,
8F61EDD81AD1A6DE00F7F8B6 /* Delegates */,
8F61EDD91AD1A72A00F7F8B6 /* Enums */,
);
path = CVCalendar;
sourceTree = "<group>";
};
8F61EDD21AD1A5C800F7F8B6 /* Models */ = {
isa = PBXGroup;
children = (
55E122481A588CC50013B002 /* CVCalendarViewAppearance.swift */,
55E122491A588CC50013B002 /* CVCalendarViewAppearanceDelegate.swift */,
55E1224A1A588CC50013B002 /* CVCalendarViewDelegate.swift */,
55E1224C1A588CC50013B002 /* CVCircleView.swift */,
55E122441A588CC50013B002 /* CVCalendarRenderer.swift */,
55E1224D1A588CC50013B002 /* CVDate.swift */,
8F02AC081AAC95E8006D1914 /* ContentViews */,
8FEB39991AA9D3CD00A8AC8D /* Range */,
8F1080B41AB89B5000D9FAC6 /* New */,
8F1080D21AB8C84600D9FAC6 /* CVSet.swift */,
);
path = CVCalendar;
name = Models;
sourceTree = "<group>";
};
8F02AC081AAC95E8006D1914 /* ContentViews */ = {
8F61EDD31AD1A5CD00F7F8B6 /* Controllers */ = {
isa = PBXGroup;
children = (
5535246C1A794AFA00EE9FDE /* CVCalendarContentViewController.swift */,
5534574F1A75176E00370955 /* CVCalendarMonthContentView.swift */,
553319261A7294AF004DF673 /* CVCalendarWeekContentView.swift */,
8F1080B51AB89B9700D9FAC6 /* CVCalendarTouchController.swift */,
55E122401A588CC50013B002 /* CVCalendarDayViewControlCoordinator.swift */,
55E122411A588CC50013B002 /* CVCalendarManager.swift */,
55E122461A588CC50013B002 /* CVCalendarViewAnimator.swift */,
5534574D1A75114B00370955 /* CVCalendarWeekContentRecovery.swift */,
);
name = ContentViews;
name = Controllers;
sourceTree = "<group>";
};
8F1080B41AB89B5000D9FAC6 /* New */ = {
8F61EDD51AD1A60F00F7F8B6 /* Main Views */ = {
isa = PBXGroup;
children = (
8F1080B51AB89B9700D9FAC6 /* CVCalendarTouchController.swift */,
8F1080B71AB89CCB00D9FAC6 /* CVSelectionType.swift */,
8F1080B91AB89CD400D9FAC6 /* CVRange.swift */,
8F1080D21AB8C84600D9FAC6 /* CVSet.swift */,
55E122451A588CC50013B002 /* CVCalendarView.swift */,
55E122421A588CC50013B002 /* CVCalendarMenuView.swift */,
);
name = New;
name = "Main Views";
sourceTree = "<group>";
};
8FEB39991AA9D3CD00A8AC8D /* Range */ = {
8F61EDD61AD1A65A00F7F8B6 /* Content Views */ = {
isa = PBXGroup;
children = (
5534574F1A75176E00370955 /* CVCalendarMonthContentView.swift */,
553319261A7294AF004DF673 /* CVCalendarWeekContentView.swift */,
);
name = "Content Views";
sourceTree = "<group>";
};
8F61EDD71AD1A67900F7F8B6 /* Unit Views */ = {
isa = PBXGroup;
children = (
55E122401A588CC50013B002 /* CVCalendarDayViewControlCoordinator.swift */,
55E122431A588CC50013B002 /* CVCalendarMonthView.swift */,
55E1224B1A588CC50013B002 /* CVCalendarWeekView.swift */,
55E1223F1A588CC50013B002 /* CVCalendarDayView.swift */,
8F827D061ABF682B005294B1 /* CVAuxiliaryView.swift */,
);
name = "Unit Views";
sourceTree = "<group>";
};
8F61EDD81AD1A6DE00F7F8B6 /* Delegates */ = {
isa = PBXGroup;
children = (
553524691A794AC400EE9FDE /* CVCalendarContentDelegate.swift */,
55E122471A588CC50013B002 /* CVCalendarViewAnimatorDelegate.swift */,
55E122491A588CC50013B002 /* CVCalendarViewAppearanceDelegate.swift */,
55E1224A1A588CC50013B002 /* CVCalendarViewDelegate.swift */,
);
name = Delegates;
sourceTree = "<group>";
};
8F61EDD91AD1A72A00F7F8B6 /* Enums */ = {
isa = PBXGroup;
children = (
8F1080B71AB89CCB00D9FAC6 /* CVSelectionType.swift */,
8F1080B91AB89CD400D9FAC6 /* CVRange.swift */,
8FDB51EE1AC09E0200F7F7AC /* CVShape.swift */,
);
name = Range;
name = Enums;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -318,19 +353,20 @@
files = (
55E122531A588CC50013B002 /* CVCalendarMonthView.swift in Sources */,
55E1225A1A588CC50013B002 /* CVCalendarViewDelegate.swift in Sources */,
8FDB51EF1AC09E0200F7F7AC /* CVShape.swift in Sources */,
55E122511A588CC50013B002 /* CVCalendarManager.swift in Sources */,
5535246D1A794AFA00EE9FDE /* CVCalendarContentViewController.swift in Sources */,
55E122541A588CC50013B002 /* CVCalendarRenderer.swift in Sources */,
55E122571A588CC50013B002 /* CVCalendarViewAnimatorDelegate.swift in Sources */,
55E122551A588CC50013B002 /* CVCalendarView.swift in Sources */,
8F827D071ABF682B005294B1 /* CVAuxiliaryView.swift in Sources */,
55E1225D1A588CC50013B002 /* CVDate.swift in Sources */,
55E122201A588CB60013B002 /* ViewController.swift in Sources */,
8F1080B81AB89CCB00D9FAC6 /* CVSelectionType.swift in Sources */,
8F1080B61AB89B9700D9FAC6 /* CVCalendarTouchController.swift in Sources */,
553457501A75176E00370955 /* CVCalendarMonthContentView.swift in Sources */,
55E122591A588CC50013B002 /* CVCalendarViewAppearanceDelegate.swift in Sources */,
55E1221E1A588CB60013B002 /* AppDelegate.swift in Sources */,
55E1225C1A588CC50013B002 /* CVCircleView.swift in Sources */,
55E1224F1A588CC50013B002 /* CVCalendarDayView.swift in Sources */,
553319271A7294AF004DF673 /* CVCalendarWeekContentView.swift in Sources */,
5534574E1A75114B00370955 /* CVCalendarWeekContentRecovery.swift in Sources */,
Expand Down Expand Up @@ -467,6 +503,7 @@
INFOPLIST_FILE = "CVCalendar Demo/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
Expand All @@ -477,6 +514,7 @@
INFOPLIST_FILE = "CVCalendar Demo/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
Expand Down
8 changes: 5 additions & 3 deletions CVCalendar Demo/CVCalendar Demo/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
</connections>
</switch>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="T1w-UY-QHC" customClass="CVCalendarView" customModule="CVCalendar_Demo" customModuleProvider="target">
<rect key="frame" x="16" y="103" width="568" height="335"/>
<rect key="frame" x="16" y="103" width="568" height="350"/>
<constraints>
<constraint firstAttribute="height" constant="335" id="3oZ-He-brt"/>
<constraint firstAttribute="height" constant="350" id="3oZ-He-brt">
<variation key="heightClass=regular-widthClass=regular" constant="480"/>
</constraint>
</constraints>
<connections>
<outlet property="calendarAppearanceDelegate" destination="vXZ-lx-hvc" id="R5d-UB-jms"/>
Expand Down Expand Up @@ -86,7 +88,7 @@
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="808" y="547"/>
<point key="canvasLocation" x="807.75" y="546.75"/>
</scene>
</scenes>
<resources>
Expand Down
10 changes: 6 additions & 4 deletions CVCalendar Demo/CVCalendar Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,21 @@ extension ViewController: CVCalendarViewDelegate {
}

func dotMarker(shouldShowOnDayView dayView: CVCalendarDayView) -> Bool {
if dayView.date?.day == 3 || dayView.date?.day == 5 || dayView.date?.day == 2 {
let day = dayView.date.day
if day == 3 || day == 5 || day == 2 {
return true
} else {
return false
}
}

func dotMarker(colorOnDayView dayView: CVCalendarDayView) -> UIColor {
if dayView.date?.day == 3 {
let day = dayView.date.day
if day == 3 {
return .redColor()
} else if dayView.date?.day == 5 {
} else if day == 5 {
return .blackColor()
} else if dayView.date?.day == 2 {
} else if day == 2 {
return .blueColor()
}

Expand Down
137 changes: 137 additions & 0 deletions CVCalendar Demo/CVCalendar/CVAuxiliaryView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
//
// CVAuxiliaryView.swift
// CVCalendar Demo
//
// Created by Eugene Mozharovsky on 22/03/15.
// Copyright (c) 2015 GameApp. All rights reserved.
//

import UIKit

class CVAuxiliaryView: UIView {
var shape: CVShape!
var strokeColor: UIColor! {
didSet {
setNeedsDisplay()
}
}

var fillColor: UIColor! {
didSet {
setNeedsDisplay()
}
}

let defaultFillColor = UIColor.colorFromCode(0xe74c3c)

private var radius: CGFloat {
get {
return (min(frame.height, frame.width) - 10) / 2
}
}

init(frame: CGRect, shape: CVShape) {
super.init(frame: frame)
self.shape = shape

strokeColor = UIColor.clearColor()
fillColor = UIColor.colorFromCode(0xe74c3c)

layer.cornerRadius = 5
backgroundColor = .clearColor()
}

override func didMoveToSuperview() {
setNeedsDisplay()
}

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func drawRect(rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
var path: UIBezierPath!

if let shape = shape {
switch shape {
case .RightFlag: path = rightFlagPath()
case .LeftFlag: path = leftFlagPath()
case .Circle: path = circlePath()
case .Rect: path = rectPath()
}
}

strokeColor.setStroke()
fillColor.setFill()

if let path = path {
path.lineWidth = 1
path.stroke()
path.fill()
}
}

deinit {
println("Deinited")
}
}

extension CVAuxiliaryView {
func circlePath() -> UIBezierPath {
let arcCenter = CGPointMake(frame.width / 2, frame.height / 2)
let startAngle = CGFloat(0)
let endAngle = CGFloat(M_PI * 2.0)
let clockwise = true

let path = UIBezierPath(arcCenter: arcCenter, radius: radius, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise)

return path

}

func rightFlagPath() -> UIBezierPath {
let appearance = Appearance.sharedCalendarViewAppearance
let offset = appearance.spaceBetweenDayViews!

let flag = UIBezierPath()
flag.moveToPoint(CGPointMake(bounds.width / 2, bounds.height / 2 - radius))
flag.addLineToPoint(CGPointMake(bounds.width, bounds.height / 2 - radius))
flag.addLineToPoint(CGPointMake(bounds.width, bounds.height / 2 + radius ))
flag.addLineToPoint(CGPointMake(bounds.width / 2, bounds.height / 2 + radius))

var path = CGPathCreateMutable()
CGPathAddPath(path, nil, circlePath().CGPath)
CGPathAddPath(path, nil, flag.CGPath)

return UIBezierPath(CGPath: path)
}

func leftFlagPath() -> UIBezierPath {
let flag = UIBezierPath()
flag.moveToPoint(CGPointMake(bounds.width / 2, bounds.height / 2 + radius))
flag.addLineToPoint(CGPointMake(0, bounds.height / 2 + radius))
flag.addLineToPoint(CGPointMake(0, bounds.height / 2 - radius))
flag.addLineToPoint(CGPointMake(bounds.width / 2, bounds.height / 2 - radius))

var path = CGPathCreateMutable()
CGPathAddPath(path, nil, circlePath().CGPath)
CGPathAddPath(path, nil, flag.CGPath)

return UIBezierPath(CGPath: path)
}

func rectPath() -> UIBezierPath {
let midX = bounds.width / 2
let midY = bounds.height / 2

let appearance = Appearance.sharedCalendarViewAppearance
let offset = appearance.spaceBetweenDayViews!

println("offset = \(offset)")

let path = UIBezierPath(rect: CGRectMake(0 - offset, midY - radius, bounds.width + offset / 2, radius * 2))

return path
}
}
6 changes: 3 additions & 3 deletions CVCalendar Demo/CVCalendar/CVCalendarContentDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import UIKit

protocol CVCalendarContentDelegate: UIScrollViewDelegate {
func updateFrames()
func performedDayViewSelection(dayView: CVCalendarDayView)
func presentNextView(dayView: CVCalendarDayView?)
func presentPreviousView(dayView: CVCalendarDayView?)
func performedDayViewSelection(dayView: DayView)
func presentNextView(dayView: DayView?)
func presentPreviousView(dayView: DayView?)
func updateDayViews(hidden: Bool)
func togglePresentedDate(date: NSDate)
}
Loading

0 comments on commit 36712c6

Please sign in to comment.