Skip to content

Commit cfddf4e

Browse files
committed
Merge pull request #9 from Urkman/master
Awesome extensions to Calendar
2 parents 7946660 + 4783b5e commit cfddf4e

11 files changed

+163
-49
lines changed

EPCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
"idiom" : "ipad",
6060
"size" : "76x76",
6161
"scale" : "2x"
62+
},
63+
{
64+
"idiom" : "ipad",
65+
"size" : "83.5x83.5",
66+
"scale" : "2x"
6267
}
6368
],
6469
"info" : {
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"info" : {
3+
"version" : 1,
4+
"author" : "xcode"
5+
}
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "universal",
5+
"filename" : "background_image.jpg",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "universal",
10+
"scale" : "2x"
11+
},
12+
{
13+
"idiom" : "universal",
14+
"scale" : "3x"
15+
}
16+
],
17+
"info" : {
18+
"version" : 1,
19+
"author" : "xcode"
20+
}
21+
}
Loading

EPCalendar/EPCalendarPicker/EPCalendarCell1.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EPCalendarCell1: UICollectionViewCell {
2525
}
2626

2727
func deSelectedForLabelColor(color: UIColor) {
28-
self.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor
28+
self.lblDay.layer.backgroundColor = UIColor.clearColor().CGColor
2929
self.lblDay.textColor = color
3030
}
3131

EPCalendar/EPCalendarPicker/EPCalendarCell1.xib

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9059" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
55
</dependencies>
66
<objects>
77
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -22,7 +22,7 @@
2222
</subviews>
2323
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
2424
</view>
25-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
25+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
2626
<constraints>
2727
<constraint firstItem="cqZ-GD-NWb" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" constant="5" id="1vq-0V-sru"/>
2828
<constraint firstAttribute="trailing" secondItem="cqZ-GD-NWb" secondAttribute="trailing" constant="5" id="JFc-pV-bti"/>

EPCalendar/EPCalendarPicker/EPCalendarConstants.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ struct EPDefaults {
1515
static let multiSelection = false
1616

1717
//Colors
18+
static let dayDisabledTintColor = UIColor.lightGrayColor()
1819
static let weekdayTintColor = EPColors.EmeraldColor
1920
static let weekendTintColor = EPColors.PomegranateColor
2021
static let dateSelectionColor = EPColors.PeterRiverColor
2122
static let monthTitleColor = EPColors.PumpkinColor
2223
static let todayTintColor = EPColors.AmethystColor
24+
2325
static let tintColor = EPColors.PomegranateColor
26+
static let barTintColor = UIColor.whiteColor()
2427

2528
//HeaderSize
2629
static let headerSize = CGSizeMake(100,60)
27-
2830
}
2931

3032
struct EPColors{

EPCalendar/EPCalendarPicker/EPCalendarHeaderView.swift

+50-17
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,64 @@ import UIKit
1010

1111
class EPCalendarHeaderView: UICollectionReusableView {
1212

13-
@IBOutlet weak var lblSunday: UILabel!
14-
@IBOutlet weak var lblMonday: UILabel!
15-
@IBOutlet weak var lblTuesday: UILabel!
16-
@IBOutlet weak var lblWednesday: UILabel!
17-
@IBOutlet weak var lblThursday: UILabel!
18-
@IBOutlet weak var lblFriday: UILabel!
19-
@IBOutlet weak var lblSaturday: UILabel!
13+
@IBOutlet weak var lblFirst: UILabel!
14+
@IBOutlet weak var lblSecond: UILabel!
15+
@IBOutlet weak var lblThird: UILabel!
16+
@IBOutlet weak var lblFourth: UILabel!
17+
@IBOutlet weak var lblFifth: UILabel!
18+
@IBOutlet weak var lblSixth: UILabel!
19+
@IBOutlet weak var lblSeventh: UILabel!
2020
@IBOutlet weak var lblTitle: UILabel!
2121

2222
override func awakeFromNib() {
2323
super.awakeFromNib()
24-
// Initialization code
24+
25+
let calendar = NSCalendar.currentCalendar()
26+
let weeksDayList = calendar.shortWeekdaySymbols
27+
28+
if NSCalendar.currentCalendar().firstWeekday == 2 {
29+
lblFirst.text = weeksDayList[1]
30+
lblSecond.text = weeksDayList[2]
31+
lblThird.text = weeksDayList[3]
32+
lblFourth.text = weeksDayList[4]
33+
lblFifth.text = weeksDayList[5]
34+
lblSixth.text = weeksDayList[6]
35+
lblSeventh.text = weeksDayList[0]
36+
} else {
37+
lblFirst.text = weeksDayList[0]
38+
lblSecond.text = weeksDayList[1]
39+
lblThird.text = weeksDayList[2]
40+
lblFourth.text = weeksDayList[3]
41+
lblFifth.text = weeksDayList[4]
42+
lblSixth.text = weeksDayList[5]
43+
lblSeventh.text = weeksDayList[6]
44+
}
2545
}
2646

27-
func updateWeekendLabelColor(color: UIColor) {
28-
lblSaturday.textColor = color
29-
lblSunday.textColor = color
47+
func updateWeekendLabelColor(color: UIColor)
48+
{
49+
if NSCalendar.currentCalendar().firstWeekday == 2 {
50+
lblSixth.textColor = color
51+
lblSeventh.textColor = color
52+
} else {
53+
lblFirst.textColor = color
54+
lblSeventh.textColor = color
55+
}
3056
}
3157

3258
func updateWeekdaysLabelColor(color: UIColor) {
33-
lblMonday.textColor = color
34-
lblTuesday.textColor = color
35-
lblWednesday.textColor = color
36-
lblThursday.textColor = color
37-
lblFriday.textColor = color
59+
if NSCalendar.currentCalendar().firstWeekday == 2 {
60+
lblFirst.textColor = color
61+
lblSecond.textColor = color
62+
lblThird.textColor = color
63+
lblFourth.textColor = color
64+
lblFifth.textColor = color
65+
} else {
66+
lblSecond.textColor = color
67+
lblThird.textColor = color
68+
lblFourth.textColor = color
69+
lblFifth.textColor = color
70+
lblSixth.textColor = color
71+
}
3872
}
39-
4073
}

EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9059" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
33
<dependencies>
4-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
4+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
55
</dependencies>
66
<objects>
77
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
@@ -56,7 +56,7 @@
5656
<nil key="highlightedColor"/>
5757
</label>
5858
</subviews>
59-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
59+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
6060
<constraints>
6161
<constraint firstItem="Lt7-Ft-F77" firstAttribute="width" secondItem="XtS-fH-RZb" secondAttribute="width" id="02a-30-ri5"/>
6262
<constraint firstItem="xQs-3z-REx" firstAttribute="width" secondItem="XtS-fH-RZb" secondAttribute="width" id="2Hg-4M-IYf"/>
@@ -115,14 +115,14 @@
115115
<constraint firstAttribute="trailing" secondItem="hne-Qq-Jmo" secondAttribute="trailing" id="p8x-1d-Vdi"/>
116116
</constraints>
117117
<connections>
118-
<outlet property="lblFriday" destination="l9N-Fd-tou" id="Umx-ZD-TcW"/>
119-
<outlet property="lblMonday" destination="86w-0y-ey8" id="rTN-Qb-BsA"/>
120-
<outlet property="lblSaturday" destination="xQs-3z-REx" id="jfp-J0-X2N"/>
121-
<outlet property="lblSunday" destination="XtS-fH-RZb" id="X8c-yd-Q8G"/>
122-
<outlet property="lblThursday" destination="ua0-Bb-Dg2" id="Tia-w0-HS2"/>
118+
<outlet property="lblFifth" destination="ua0-Bb-Dg2" id="Uvh-SJ-xIV"/>
119+
<outlet property="lblFirst" destination="XtS-fH-RZb" id="j5b-Nz-HXI"/>
120+
<outlet property="lblFourth" destination="Lt7-Ft-F77" id="QDq-MX-qNK"/>
121+
<outlet property="lblSecond" destination="86w-0y-ey8" id="HDD-PK-onx"/>
122+
<outlet property="lblSeventh" destination="xQs-3z-REx" id="HNI-h5-3W3"/>
123+
<outlet property="lblSixth" destination="l9N-Fd-tou" id="gSy-G5-Klb"/>
124+
<outlet property="lblThird" destination="Z6P-SX-pQe" id="jkE-4x-664"/>
123125
<outlet property="lblTitle" destination="hne-Qq-Jmo" id="NOD-QZ-epv"/>
124-
<outlet property="lblTuesday" destination="Z6P-SX-pQe" id="28l-uq-BRF"/>
125-
<outlet property="lblWednesday" destination="Lt7-Ft-F77" id="og9-6F-npH"/>
126126
</connections>
127127
<point key="canvasLocation" x="245" y="325"/>
128128
</collectionReusableView>

EPCalendar/EPCalendarPicker/EPCalendarPicker.swift

+51-16
Original file line numberDiff line numberDiff line change
@@ -11,51 +11,69 @@ import UIKit
1111
private let reuseIdentifier = "Cell"
1212

1313
@objc public protocol EPCalendarPickerDelegate{
14-
1514
optional func epCalendarPicker(_: EPCalendarPicker, didCancel error : NSError)
1615
optional func epCalendarPicker(_: EPCalendarPicker, didSelectDate date : NSDate)
1716
optional func epCalendarPicker(_: EPCalendarPicker, didSelectMultipleDate dates : [NSDate])
18-
1917
}
2018

21-
2219
public class EPCalendarPicker: UICollectionViewController {
2320

2421
public var calendarDelegate : EPCalendarPickerDelegate?
2522
public var multiSelectEnabled: Bool
2623
public var showsTodaysButton: Bool = true
2724
private var arrSelectedDates = [NSDate]()
2825
public var tintColor: UIColor
26+
27+
public var dayDisabledTintColor: UIColor
2928
public var weekdayTintColor: UIColor
3029
public var weekendTintColor: UIColor
3130
public var todayTintColor: UIColor
3231
public var dateSelectionColor: UIColor
3332
public var monthTitleColor: UIColor
3433

34+
// new options
35+
public var startDate: NSDate?
36+
public var hightlightsToday: Bool = true
37+
public var hideDaysFromOtherMonth: Bool = false
38+
public var barTintColor: UIColor
39+
40+
public var backgroundImage: UIImage?
41+
public var backgroundColor: UIColor?
3542

3643
private(set) public var startYear: Int
3744
private(set) public var endYear: Int
3845

3946
override public func viewDidLoad() {
4047
super.viewDidLoad()
41-
self.title = "Date Picker"
42-
self.collectionView?.delegate = self
43-
self.collectionView?.backgroundColor = UIColor.whiteColor()
48+
49+
// setup Navigationbar
4450
self.navigationController?.navigationBar.tintColor = self.tintColor
51+
self.navigationController?.navigationBar.barTintColor = self.barTintColor
52+
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:self.tintColor]
53+
54+
// setup collectionview
55+
self.collectionView?.delegate = self
56+
self.collectionView?.backgroundColor = UIColor.clearColor()
4557
self.collectionView?.showsHorizontalScrollIndicator = false
4658
self.collectionView?.showsVerticalScrollIndicator = false
4759

48-
4960
// Register cell classes
5061
self.collectionView!.registerNib(UINib(nibName: "EPCalendarCell1", bundle: NSBundle(forClass: EPCalendarPicker.self )), forCellWithReuseIdentifier: reuseIdentifier)
62+
self.collectionView!.registerNib(UINib(nibName: "EPCalendarHeaderView", bundle: NSBundle(forClass: EPCalendarPicker.self )), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header")
5163

52-
self.collectionView!.registerNib(UINib(nibName: "EPCalendarHeaderView", bundle: NSBundle(forClass: EPCalendarPicker.self )), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "Header")
5364
inititlizeBarButtons()
5465

5566
dispatch_async(dispatch_get_main_queue()) { () -> Void in
5667
self.scrollToToday()
5768
}
58-
// Do any additional setup after loading the view.
69+
70+
if backgroundImage != nil {
71+
self.collectionView!.backgroundView = UIImageView(image: backgroundImage)
72+
} else if backgroundColor != nil {
73+
self.collectionView?.backgroundColor = backgroundColor
74+
} else {
75+
self.collectionView?.backgroundColor = UIColor.whiteColor()
76+
}
5977
}
6078

6179

@@ -113,6 +131,8 @@ public class EPCalendarPicker: UICollectionViewController {
113131

114132
//Text color initializations
115133
self.tintColor = EPDefaults.tintColor
134+
self.barTintColor = EPDefaults.barTintColor
135+
self.dayDisabledTintColor = EPDefaults.dayDisabledTintColor
116136
self.weekdayTintColor = EPDefaults.weekdayTintColor
117137
self.weekendTintColor = EPDefaults.weekendTintColor
118138
self.dateSelectionColor = EPDefaults.dateSelectionColor
@@ -129,7 +149,6 @@ public class EPCalendarPicker: UICollectionViewController {
129149
self.arrSelectedDates.appendContentsOf(selectedDates!)
130150
}
131151
super.init(collectionViewLayout: layout)
132-
133152
}
134153

135154

@@ -193,22 +212,37 @@ public class EPCalendarPicker: UICollectionViewController {
193212
}
194213
if (currentDate > nextMonthFirstDay) {
195214
cell.isCellSelectable = false
196-
cell.lblDay.textColor = EPColors.LightGrayColor
215+
if hideDaysFromOtherMonth {
216+
cell.lblDay.textColor = UIColor.clearColor()
217+
} else {
218+
cell.lblDay.textColor = self.dayDisabledTintColor
219+
}
197220
}
198-
if currentDate.isToday() {
221+
if currentDate.isToday() && hightlightsToday {
199222
cell.setTodayCellColor(todayTintColor)
200223
}
201224

225+
if startDate != nil {
226+
if NSCalendar.currentCalendar().startOfDayForDate(cell.currentDate) < NSCalendar.currentCalendar().startOfDayForDate(startDate!) {
227+
cell.isCellSelectable = false
228+
cell.lblDay.textColor = self.dayDisabledTintColor
229+
}
230+
}
202231
}
203232
}
204233
else {
205234
cell.isCellSelectable = false
206235
let previousDay = firstDayOfThisMonth.dateByAddingDays(-( prefixDays - indexPath.row))
207236
cell.currentDate = previousDay
208237
cell.lblDay.text = "\(previousDay.day())"
209-
cell.lblDay.textColor = EPColors.LightGrayColor
210-
cell.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor
238+
if hideDaysFromOtherMonth {
239+
cell.lblDay.textColor = UIColor.clearColor()
240+
} else {
241+
cell.lblDay.textColor = self.dayDisabledTintColor
242+
}
211243
}
244+
245+
cell.backgroundColor = UIColor.clearColor()
212246
return cell
213247
}
214248

@@ -238,11 +272,12 @@ public class EPCalendarPicker: UICollectionViewController {
238272
header.lblTitle.textColor = monthTitleColor
239273
header.updateWeekdaysLabelColor(weekdayTintColor)
240274
header.updateWeekendLabelColor(weekendTintColor)
275+
header.backgroundColor = UIColor.clearColor()
276+
241277
return header;
242278
}
243279

244280
return UICollectionReusableView()
245-
246281
}
247282

248283
override public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
@@ -274,7 +309,7 @@ public class EPCalendarPicker: UICollectionViewController {
274309
else {
275310
cell.deSelectedForLabelColor(weekdayTintColor)
276311
}
277-
if cell.currentDate.isToday() {
312+
if cell.currentDate.isToday() && hightlightsToday{
278313
cell.setTodayCellColor(todayTintColor)
279314
}
280315
}

EPCalendar/ViewController.swift

+13-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,20 @@ class ViewController: UIViewController, EPCalendarPickerDelegate {
2424
}
2525

2626
@IBAction func onTouchShowMeCalendarButton(sender: AnyObject) {
27-
let calendarPicker = EPCalendarPicker(startYear: 2015, endYear: 2017, multiSelection: true, selectedDates: [NSDate()])
27+
let calendarPicker = EPCalendarPicker(startYear: 2016, endYear: 2017, multiSelection: false, selectedDates: [])
2828
calendarPicker.calendarDelegate = self
29+
calendarPicker.startDate = NSDate()
30+
calendarPicker.hightlightsToday = false
31+
calendarPicker.showsTodaysButton = false
32+
calendarPicker.hideDaysFromOtherMonth = true
33+
calendarPicker.tintColor = UIColor.blackColor()
34+
calendarPicker.barTintColor = UIColor.greenColor()
35+
calendarPicker.dayDisabledTintColor = UIColor.grayColor()
36+
calendarPicker.title = "Title"
37+
38+
// calendarPicker.backgroundImage = UIImage(named: "background_image")
39+
// calendarPicker.backgroundColor = UIColor.blueColor()
40+
2941
let navigationController = UINavigationController(rootViewController: calendarPicker)
3042
self.presentViewController(navigationController, animated: true, completion: nil)
3143
}

0 commit comments

Comments
 (0)