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

some extensions #9

Merged
merged 4 commits into from
Feb 26, 2016
Merged
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
5 changes: 5 additions & 0 deletions EPCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
Expand Down
6 changes: 6 additions & 0 deletions EPCalendar/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
21 changes: 21 additions & 0 deletions EPCalendar/Assets.xcassets/background_image.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "background_image.jpg",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion EPCalendar/EPCalendarPicker/EPCalendarCell1.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class EPCalendarCell1: UICollectionViewCell {
}

func deSelectedForLabelColor(color: UIColor) {
self.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor
self.lblDay.layer.backgroundColor = UIColor.clearColor().CGColor
self.lblDay.textColor = color
}

Expand Down
6 changes: 3 additions & 3 deletions EPCalendar/EPCalendarPicker/EPCalendarCell1.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9059" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand All @@ -22,7 +22,7 @@
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="cqZ-GD-NWb" firstAttribute="leading" secondItem="gTV-IL-0wX" secondAttribute="leading" constant="5" id="1vq-0V-sru"/>
<constraint firstAttribute="trailing" secondItem="cqZ-GD-NWb" secondAttribute="trailing" constant="5" id="JFc-pV-bti"/>
Expand Down
4 changes: 3 additions & 1 deletion EPCalendar/EPCalendarPicker/EPCalendarConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ struct EPDefaults {
static let multiSelection = false

//Colors
static let dayDisabledTintColor = UIColor.lightGrayColor()
static let weekdayTintColor = EPColors.EmeraldColor
static let weekendTintColor = EPColors.PomegranateColor
static let dateSelectionColor = EPColors.PeterRiverColor
static let monthTitleColor = EPColors.PumpkinColor
static let todayTintColor = EPColors.AmethystColor

static let tintColor = EPColors.PomegranateColor
static let barTintColor = UIColor.whiteColor()

//HeaderSize
static let headerSize = CGSizeMake(100,60)

}

struct EPColors{
Expand Down
67 changes: 50 additions & 17 deletions EPCalendar/EPCalendarPicker/EPCalendarHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,64 @@ import UIKit

class EPCalendarHeaderView: UICollectionReusableView {

@IBOutlet weak var lblSunday: UILabel!
@IBOutlet weak var lblMonday: UILabel!
@IBOutlet weak var lblTuesday: UILabel!
@IBOutlet weak var lblWednesday: UILabel!
@IBOutlet weak var lblThursday: UILabel!
@IBOutlet weak var lblFriday: UILabel!
@IBOutlet weak var lblSaturday: UILabel!
@IBOutlet weak var lblFirst: UILabel!
@IBOutlet weak var lblSecond: UILabel!
@IBOutlet weak var lblThird: UILabel!
@IBOutlet weak var lblFourth: UILabel!
@IBOutlet weak var lblFifth: UILabel!
@IBOutlet weak var lblSixth: UILabel!
@IBOutlet weak var lblSeventh: UILabel!
@IBOutlet weak var lblTitle: UILabel!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code

let calendar = NSCalendar.currentCalendar()
let weeksDayList = calendar.shortWeekdaySymbols

if NSCalendar.currentCalendar().firstWeekday == 2 {
lblFirst.text = weeksDayList[1]
lblSecond.text = weeksDayList[2]
lblThird.text = weeksDayList[3]
lblFourth.text = weeksDayList[4]
lblFifth.text = weeksDayList[5]
lblSixth.text = weeksDayList[6]
lblSeventh.text = weeksDayList[0]
} else {
lblFirst.text = weeksDayList[0]
lblSecond.text = weeksDayList[1]
lblThird.text = weeksDayList[2]
lblFourth.text = weeksDayList[3]
lblFifth.text = weeksDayList[4]
lblSixth.text = weeksDayList[5]
lblSeventh.text = weeksDayList[6]
}
}

func updateWeekendLabelColor(color: UIColor) {
lblSaturday.textColor = color
lblSunday.textColor = color
func updateWeekendLabelColor(color: UIColor)
{
if NSCalendar.currentCalendar().firstWeekday == 2 {
lblSixth.textColor = color
lblSeventh.textColor = color
} else {
lblFirst.textColor = color
lblSeventh.textColor = color
}
}

func updateWeekdaysLabelColor(color: UIColor) {
lblMonday.textColor = color
lblTuesday.textColor = color
lblWednesday.textColor = color
lblThursday.textColor = color
lblFriday.textColor = color
if NSCalendar.currentCalendar().firstWeekday == 2 {
lblFirst.textColor = color
lblSecond.textColor = color
lblThird.textColor = color
lblFourth.textColor = color
lblFifth.textColor = color
} else {
lblSecond.textColor = color
lblThird.textColor = color
lblFourth.textColor = color
lblFifth.textColor = color
lblSixth.textColor = color
}
}

}
20 changes: 10 additions & 10 deletions EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9059" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
Expand Down Expand Up @@ -56,7 +56,7 @@
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Lt7-Ft-F77" firstAttribute="width" secondItem="XtS-fH-RZb" secondAttribute="width" id="02a-30-ri5"/>
<constraint firstItem="xQs-3z-REx" firstAttribute="width" secondItem="XtS-fH-RZb" secondAttribute="width" id="2Hg-4M-IYf"/>
Expand Down Expand Up @@ -115,14 +115,14 @@
<constraint firstAttribute="trailing" secondItem="hne-Qq-Jmo" secondAttribute="trailing" id="p8x-1d-Vdi"/>
</constraints>
<connections>
<outlet property="lblFriday" destination="l9N-Fd-tou" id="Umx-ZD-TcW"/>
<outlet property="lblMonday" destination="86w-0y-ey8" id="rTN-Qb-BsA"/>
<outlet property="lblSaturday" destination="xQs-3z-REx" id="jfp-J0-X2N"/>
<outlet property="lblSunday" destination="XtS-fH-RZb" id="X8c-yd-Q8G"/>
<outlet property="lblThursday" destination="ua0-Bb-Dg2" id="Tia-w0-HS2"/>
<outlet property="lblFifth" destination="ua0-Bb-Dg2" id="Uvh-SJ-xIV"/>
<outlet property="lblFirst" destination="XtS-fH-RZb" id="j5b-Nz-HXI"/>
<outlet property="lblFourth" destination="Lt7-Ft-F77" id="QDq-MX-qNK"/>
<outlet property="lblSecond" destination="86w-0y-ey8" id="HDD-PK-onx"/>
<outlet property="lblSeventh" destination="xQs-3z-REx" id="HNI-h5-3W3"/>
<outlet property="lblSixth" destination="l9N-Fd-tou" id="gSy-G5-Klb"/>
<outlet property="lblThird" destination="Z6P-SX-pQe" id="jkE-4x-664"/>
<outlet property="lblTitle" destination="hne-Qq-Jmo" id="NOD-QZ-epv"/>
<outlet property="lblTuesday" destination="Z6P-SX-pQe" id="28l-uq-BRF"/>
<outlet property="lblWednesday" destination="Lt7-Ft-F77" id="og9-6F-npH"/>
</connections>
<point key="canvasLocation" x="245" y="325"/>
</collectionReusableView>
Expand Down
67 changes: 51 additions & 16 deletions EPCalendar/EPCalendarPicker/EPCalendarPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,69 @@ import UIKit
private let reuseIdentifier = "Cell"

@objc public protocol EPCalendarPickerDelegate{

optional func epCalendarPicker(_: EPCalendarPicker, didCancel error : NSError)
optional func epCalendarPicker(_: EPCalendarPicker, didSelectDate date : NSDate)
optional func epCalendarPicker(_: EPCalendarPicker, didSelectMultipleDate dates : [NSDate])

}


public class EPCalendarPicker: UICollectionViewController {

public var calendarDelegate : EPCalendarPickerDelegate?
public var multiSelectEnabled: Bool
public var showsTodaysButton: Bool = true
private var arrSelectedDates = [NSDate]()
public var tintColor: UIColor

public var dayDisabledTintColor: UIColor
public var weekdayTintColor: UIColor
public var weekendTintColor: UIColor
public var todayTintColor: UIColor
public var dateSelectionColor: UIColor
public var monthTitleColor: UIColor

// new options
public var startDate: NSDate?
public var hightlightsToday: Bool = true
public var hideDaysFromOtherMonth: Bool = false
public var barTintColor: UIColor

public var backgroundImage: UIImage?
public var backgroundColor: UIColor?

private(set) public var startYear: Int
private(set) public var endYear: Int

override public func viewDidLoad() {
super.viewDidLoad()
self.title = "Date Picker"
self.collectionView?.delegate = self
self.collectionView?.backgroundColor = UIColor.whiteColor()

// setup Navigationbar
self.navigationController?.navigationBar.tintColor = self.tintColor
self.navigationController?.navigationBar.barTintColor = self.barTintColor
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:self.tintColor]

// setup collectionview
self.collectionView?.delegate = self
self.collectionView?.backgroundColor = UIColor.clearColor()
self.collectionView?.showsHorizontalScrollIndicator = false
self.collectionView?.showsVerticalScrollIndicator = false


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

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

dispatch_async(dispatch_get_main_queue()) { () -> Void in
self.scrollToToday()
}
// Do any additional setup after loading the view.

if backgroundImage != nil {
self.collectionView!.backgroundView = UIImageView(image: backgroundImage)
} else if backgroundColor != nil {
self.collectionView?.backgroundColor = backgroundColor
} else {
self.collectionView?.backgroundColor = UIColor.whiteColor()
}
}


Expand Down Expand Up @@ -113,6 +131,8 @@ public class EPCalendarPicker: UICollectionViewController {

//Text color initializations
self.tintColor = EPDefaults.tintColor
self.barTintColor = EPDefaults.barTintColor
self.dayDisabledTintColor = EPDefaults.dayDisabledTintColor
self.weekdayTintColor = EPDefaults.weekdayTintColor
self.weekendTintColor = EPDefaults.weekendTintColor
self.dateSelectionColor = EPDefaults.dateSelectionColor
Expand All @@ -129,7 +149,6 @@ public class EPCalendarPicker: UICollectionViewController {
self.arrSelectedDates.appendContentsOf(selectedDates!)
}
super.init(collectionViewLayout: layout)

}


Expand Down Expand Up @@ -193,22 +212,37 @@ public class EPCalendarPicker: UICollectionViewController {
}
if (currentDate > nextMonthFirstDay) {
cell.isCellSelectable = false
cell.lblDay.textColor = EPColors.LightGrayColor
if hideDaysFromOtherMonth {
cell.lblDay.textColor = UIColor.clearColor()
} else {
cell.lblDay.textColor = self.dayDisabledTintColor
}
}
if currentDate.isToday() {
if currentDate.isToday() && hightlightsToday {
cell.setTodayCellColor(todayTintColor)
}

if startDate != nil {
if NSCalendar.currentCalendar().startOfDayForDate(cell.currentDate) < NSCalendar.currentCalendar().startOfDayForDate(startDate!) {
cell.isCellSelectable = false
cell.lblDay.textColor = self.dayDisabledTintColor
}
}
}
}
else {
cell.isCellSelectable = false
let previousDay = firstDayOfThisMonth.dateByAddingDays(-( prefixDays - indexPath.row))
cell.currentDate = previousDay
cell.lblDay.text = "\(previousDay.day())"
cell.lblDay.textColor = EPColors.LightGrayColor
cell.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor
if hideDaysFromOtherMonth {
cell.lblDay.textColor = UIColor.clearColor()
} else {
cell.lblDay.textColor = self.dayDisabledTintColor
}
}

cell.backgroundColor = UIColor.clearColor()
return cell
}

Expand Down Expand Up @@ -238,11 +272,12 @@ public class EPCalendarPicker: UICollectionViewController {
header.lblTitle.textColor = monthTitleColor
header.updateWeekdaysLabelColor(weekdayTintColor)
header.updateWeekendLabelColor(weekendTintColor)
header.backgroundColor = UIColor.clearColor()

return header;
}

return UICollectionReusableView()

}

override public func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
Expand Down Expand Up @@ -274,7 +309,7 @@ public class EPCalendarPicker: UICollectionViewController {
else {
cell.deSelectedForLabelColor(weekdayTintColor)
}
if cell.currentDate.isToday() {
if cell.currentDate.isToday() && hightlightsToday{
cell.setTodayCellColor(todayTintColor)
}
}
Expand Down
14 changes: 13 additions & 1 deletion EPCalendar/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,20 @@ class ViewController: UIViewController, EPCalendarPickerDelegate {
}

@IBAction func onTouchShowMeCalendarButton(sender: AnyObject) {
let calendarPicker = EPCalendarPicker(startYear: 2015, endYear: 2017, multiSelection: true, selectedDates: [NSDate()])
let calendarPicker = EPCalendarPicker(startYear: 2016, endYear: 2017, multiSelection: false, selectedDates: [])
calendarPicker.calendarDelegate = self
calendarPicker.startDate = NSDate()
calendarPicker.hightlightsToday = false
calendarPicker.showsTodaysButton = false
calendarPicker.hideDaysFromOtherMonth = true
calendarPicker.tintColor = UIColor.blackColor()
calendarPicker.barTintColor = UIColor.greenColor()
calendarPicker.dayDisabledTintColor = UIColor.grayColor()
calendarPicker.title = "Title"

// calendarPicker.backgroundImage = UIImage(named: "background_image")
// calendarPicker.backgroundColor = UIColor.blueColor()

let navigationController = UINavigationController(rootViewController: calendarPicker)
self.presentViewController(navigationController, animated: true, completion: nil)
}
Expand Down