From 222e3144e66f6141bc33a69c695be44e86aeb64a Mon Sep 17 00:00:00 2001 From: Stefan Sturm Date: Thu, 25 Feb 2016 12:39:56 +0100 Subject: [PATCH 1/4] some extensions - add possibility to start week on monday - add possibility to set a startDate - add possibility to hide days from other month - add possibility to not highlight today --- .../EPCalendarPicker/EPCalendarCell1.xib | 4 +- .../EPCalendarHeaderView.swift | 67 ++++++++++++++----- .../EPCalendarPicker/EPCalendarHeaderView.xib | 18 ++--- .../EPCalendarPicker/EPCalendarPicker.swift | 26 +++++-- EPCalendar/ViewController.swift | 7 +- 5 files changed, 89 insertions(+), 33 deletions(-) diff --git a/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib b/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib index 10b803c..05cdadb 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib +++ b/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib @@ -1,7 +1,7 @@ - + - + diff --git a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.swift b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.swift index 587d570..5726665 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.swift @@ -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 + } } - } diff --git a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib index 1f1d49e..b63218c 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib +++ b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib @@ -1,7 +1,7 @@ - + - + @@ -115,14 +115,14 @@ - - - - - + + + + + + + - - diff --git a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift index ee9607d..ecab889 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift @@ -32,6 +32,10 @@ public class EPCalendarPicker: UICollectionViewController { public var dateSelectionColor: UIColor public var monthTitleColor: UIColor + // new options + public var startDate: NSDate? + public var hightlightsToday: Bool = true + public var hideDaysFromOtherMonth: Bool = false private(set) public var startYear: Int private(set) public var endYear: Int @@ -193,12 +197,22 @@ 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 = EPColors.LightGrayColor + } } - 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 = EPColors.LightGrayColor + } + } } } else { @@ -206,7 +220,11 @@ public class EPCalendarPicker: UICollectionViewController { let previousDay = firstDayOfThisMonth.dateByAddingDays(-( prefixDays - indexPath.row)) cell.currentDate = previousDay cell.lblDay.text = "\(previousDay.day())" - cell.lblDay.textColor = EPColors.LightGrayColor + if hideDaysFromOtherMonth { + cell.lblDay.textColor = UIColor.clearColor() + } else { + cell.lblDay.textColor = EPColors.LightGrayColor + } cell.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor } return cell @@ -274,7 +292,7 @@ public class EPCalendarPicker: UICollectionViewController { else { cell.deSelectedForLabelColor(weekdayTintColor) } - if cell.currentDate.isToday() { + if cell.currentDate.isToday() && hightlightsToday{ cell.setTodayCellColor(todayTintColor) } } diff --git a/EPCalendar/ViewController.swift b/EPCalendar/ViewController.swift index 3b2a9a3..325aa07 100644 --- a/EPCalendar/ViewController.swift +++ b/EPCalendar/ViewController.swift @@ -24,8 +24,13 @@ 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 + let navigationController = UINavigationController(rootViewController: calendarPicker) self.presentViewController(navigationController, animated: true, completion: nil) } From f1577280da92cab738463ef21ceb94433537bd0a Mon Sep 17 00:00:00 2001 From: Stefan Sturm Date: Thu, 25 Feb 2016 13:17:17 +0100 Subject: [PATCH 2/4] add option to change barTintColor --- EPCalendar/EPCalendarPicker/EPCalendarConstants.swift | 3 ++- EPCalendar/EPCalendarPicker/EPCalendarPicker.swift | 6 +++++- EPCalendar/ViewController.swift | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift b/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift index 5c467bb..0709190 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift @@ -20,11 +20,12 @@ struct EPDefaults { 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{ diff --git a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift index ecab889..4f92c32 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift @@ -26,6 +26,8 @@ public class EPCalendarPicker: UICollectionViewController { public var showsTodaysButton: Bool = true private var arrSelectedDates = [NSDate]() public var tintColor: UIColor + public var barTintColor: UIColor + public var weekdayTintColor: UIColor public var weekendTintColor: UIColor public var todayTintColor: UIColor @@ -46,6 +48,8 @@ public class EPCalendarPicker: UICollectionViewController { self.collectionView?.delegate = self self.collectionView?.backgroundColor = UIColor.whiteColor() self.navigationController?.navigationBar.tintColor = self.tintColor + self.navigationController?.navigationBar.barTintColor = self.barTintColor + self.collectionView?.showsHorizontalScrollIndicator = false self.collectionView?.showsVerticalScrollIndicator = false @@ -117,6 +121,7 @@ public class EPCalendarPicker: UICollectionViewController { //Text color initializations self.tintColor = EPDefaults.tintColor + self.barTintColor = EPDefaults.barTintColor self.weekdayTintColor = EPDefaults.weekdayTintColor self.weekendTintColor = EPDefaults.weekendTintColor self.dateSelectionColor = EPDefaults.dateSelectionColor @@ -133,7 +138,6 @@ public class EPCalendarPicker: UICollectionViewController { self.arrSelectedDates.appendContentsOf(selectedDates!) } super.init(collectionViewLayout: layout) - } diff --git a/EPCalendar/ViewController.swift b/EPCalendar/ViewController.swift index 325aa07..b33a62e 100644 --- a/EPCalendar/ViewController.swift +++ b/EPCalendar/ViewController.swift @@ -30,6 +30,8 @@ class ViewController: UIViewController, EPCalendarPickerDelegate { calendarPicker.hightlightsToday = false calendarPicker.showsTodaysButton = false calendarPicker.hideDaysFromOtherMonth = true + calendarPicker.tintColor = UIColor.whiteColor() + calendarPicker.barTintColor = UIColor.greenColor() let navigationController = UINavigationController(rootViewController: calendarPicker) self.presentViewController(navigationController, animated: true, completion: nil) From 8e762af1f2f6339db236b86a7cc98029e604a1f3 Mon Sep 17 00:00:00 2001 From: Stefan Sturm Date: Thu, 25 Feb 2016 14:59:50 +0100 Subject: [PATCH 3/4] add option to set background color or a background image --- .../AppIcon.appiconset/Contents.json | 5 +++ EPCalendar/Assets.xcassets/Contents.json | 6 +++ .../background_image.imageset/Contents.json | 21 ++++++++++ .../background_image.jpg | Bin 0 -> 10921 bytes .../EPCalendarPicker/EPCalendarCell1.swift | 2 +- .../EPCalendarPicker/EPCalendarCell1.xib | 2 +- .../EPCalendarPicker/EPCalendarHeaderView.xib | 2 +- .../EPCalendarPicker/EPCalendarPicker.swift | 38 ++++++++++++------ EPCalendar/ViewController.swift | 6 ++- 9 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 EPCalendar/Assets.xcassets/Contents.json create mode 100644 EPCalendar/Assets.xcassets/background_image.imageset/Contents.json create mode 100644 EPCalendar/Assets.xcassets/background_image.imageset/background_image.jpg diff --git a/EPCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json b/EPCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json index 36d2c80..eeea76c 100644 --- a/EPCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/EPCalendar/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -59,6 +59,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/EPCalendar/Assets.xcassets/Contents.json b/EPCalendar/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/EPCalendar/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/EPCalendar/Assets.xcassets/background_image.imageset/Contents.json b/EPCalendar/Assets.xcassets/background_image.imageset/Contents.json new file mode 100644 index 0000000..245b86b --- /dev/null +++ b/EPCalendar/Assets.xcassets/background_image.imageset/Contents.json @@ -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" + } +} \ No newline at end of file diff --git a/EPCalendar/Assets.xcassets/background_image.imageset/background_image.jpg b/EPCalendar/Assets.xcassets/background_image.imageset/background_image.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7c186c78b5fdd861dd685b0c6ccfdf3f54706c09 GIT binary patch literal 10921 zcmeHrcUaR&)b1o9bV86O2pB}ANE4z&2;H)R0)p#eXRX*)iYN+VAiAPbR1jRHM3Dtt zRzZ}aC_zwBgrGrebWoZ~NI+2$zB2(`b<6$k^V~o0FUicDGiT0u&pT%(gpnsB&4}tU zcm7;NARt757aDnvoROpiS&}RvDM^-;l9H5`rOL|6$jGWt6y>SvD&xnitEj1IYEPM{ zIYCcLO^s$u)0?VqXk@4{(Zt-uzf#D$h%z*2!R5*sph~WVt{hlVl^F zIv}E{OGG+`3h7ij!8D3o^X(lob;A)}#GtiBTx;zCs2`3KU8Z3!&0d(l7ne=Kf zb%>~shRNAR3YHwmlvbeUaF0ul=OD=-X=DOOEFcpDL`Zf*a*&aHHd+etH+ry$;dF~L z4gkfXb_zs>Seej`i@GAS82rUK8>xtKIQTE-ZW9FRl~i;xXVC+8pquti9tmL|y(aWc}Zf*eg9&_l@KDB42jAc-PG zS`fh{pAv^bCgLz^5C9OM%cD$i#7v+Xmq{$B9-=`!E}wCc99%z#r-%#atN~Ofnsf+I z5KbSJyfhO49z~CCbN@{QfWOr_kbxOjd6uLILj1D`b}r^mzz-sBT&uvsWGh5%1?|+G z=1-s-n_80PJyc*%UC-SeI$FyC2XTqg~|!v)>uK%pqjI;vgxzlQdM9ju2%F z(yYFRP+(UCQrHaad~Luf>XN5VnV8=!2$$fj#B5tfz#Dn8D~>h+_SN8Jor5+6`fPy4&%}XU5Guz= zh#tu2`N__Bf&n5?J3B71WE=?WU)G-Wkl-MBX8{?|B|;#H=+qV zz!lIFhg9lV2(|yG!Wy=X1@#HrHa!P9<#GN~hJC0*+OuLfh!AIvx^@R4BxUPE;GgV< zjkQFS#6(E@vk6cl-C7N0zl1G2`mGsyZ$pUYqZ>&C7Na-|q_= zu$fkLQA|NBxJDY~)~lTJAQ++I`N^K(em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CT^ZL?<*Gg*Yr?Hd;j!ikoes~2J&TMGAp z_4El(Yr~|?j0q1S8>`aGyReM%D!r(Q_Fk4tkXgvXe%K_~YwdU5d9UJe>7TQyv zjlbp=_5O#Hd94$i)i*szHB_z`a`s)L^XG?yIaRJr`O~|bGDGBRuYX)Ss;Vqr#(q@d z@m8Z~P3@S*`oY$Dk6XHfvPMu&vD}>8iK`E0)nyE~3QW|>_lD_YxOQi&g*4}81kENWaO`4YP zl7C4p-_w+KSvMp$QMSQ8a-d|MuhTpAUsSK|Q|bwesX6e*w0_!-;i(0kuccSDzP?$o zv2TXhWTM&NOcuA8MtJP~mIXy7nfsa$KIovZ_8EyJ2%k5qTvSI@%RC&c6u z>cD>T`AI1fc~?GFjSGLA@#$y6=E#hQrO$?69&+g659hG1%=RiZe!XE-I&dWO>&b7$ z>(;BKbUr=hv(xGR7gr`Tti9%Gz8DoRd?jWG{L@x;wSUxVJOEAIm*$b&-M6#Os~fjkUomxWo%@R}?^f zEq9pSMr>FeIzE~+zAyZji#O!w*2o8Q3w~;n{KHq0>9hP(z2={1U~2n2zs>pko$s7g ze>yRAO|W9-Hu)b`uiM*qsM+q!<>|V6kG;FC&-(CdP5FVh^O`0F<0?FQqvB(maw(MN zm=Z5Cn-@4|d#!DG)3vwd{k!N(J~>zX{<*Zh~bLcDKAFUoC(Jcbg z@zVQR5>In~AEmNmks{Mux!lGqdG_u$52kb8=iYP#rJ6O*>U}SSi*7iy - + diff --git a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib index b63218c..f630d86 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib +++ b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib @@ -56,7 +56,7 @@ - + diff --git a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift index 4f92c32..7ea6c7e 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift @@ -11,14 +11,11 @@ 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? @@ -26,7 +23,6 @@ public class EPCalendarPicker: UICollectionViewController { public var showsTodaysButton: Bool = true private var arrSelectedDates = [NSDate]() public var tintColor: UIColor - public var barTintColor: UIColor public var weekdayTintColor: UIColor public var weekendTintColor: UIColor @@ -38,32 +34,45 @@ public class EPCalendarPicker: UICollectionViewController { 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() + } } @@ -229,8 +238,10 @@ public class EPCalendarPicker: UICollectionViewController { } else { cell.lblDay.textColor = EPColors.LightGrayColor } - cell.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor +// cell.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor } + + cell.backgroundColor = UIColor.clearColor() return cell } @@ -260,11 +271,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) { diff --git a/EPCalendar/ViewController.swift b/EPCalendar/ViewController.swift index b33a62e..4d7fca6 100644 --- a/EPCalendar/ViewController.swift +++ b/EPCalendar/ViewController.swift @@ -30,8 +30,12 @@ class ViewController: UIViewController, EPCalendarPickerDelegate { calendarPicker.hightlightsToday = false calendarPicker.showsTodaysButton = false calendarPicker.hideDaysFromOtherMonth = true - calendarPicker.tintColor = UIColor.whiteColor() + calendarPicker.tintColor = UIColor.blackColor() calendarPicker.barTintColor = UIColor.greenColor() + 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) From 4783b5e4f7d1c49c2e24c44642a2b5ac071af72b Mon Sep 17 00:00:00 2001 From: Stefan Sturm Date: Thu, 25 Feb 2016 15:19:03 +0100 Subject: [PATCH 4/4] add property to set disabled day color --- EPCalendar/EPCalendarPicker/EPCalendarConstants.swift | 1 + EPCalendar/EPCalendarPicker/EPCalendarPicker.swift | 9 +++++---- EPCalendar/ViewController.swift | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift b/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift index 0709190..8adbca5 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift @@ -15,6 +15,7 @@ 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 diff --git a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift index 7ea6c7e..e071f8c 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift @@ -24,6 +24,7 @@ public class EPCalendarPicker: UICollectionViewController { private var arrSelectedDates = [NSDate]() public var tintColor: UIColor + public var dayDisabledTintColor: UIColor public var weekdayTintColor: UIColor public var weekendTintColor: UIColor public var todayTintColor: UIColor @@ -131,6 +132,7 @@ 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 @@ -213,7 +215,7 @@ public class EPCalendarPicker: UICollectionViewController { if hideDaysFromOtherMonth { cell.lblDay.textColor = UIColor.clearColor() } else { - cell.lblDay.textColor = EPColors.LightGrayColor + cell.lblDay.textColor = self.dayDisabledTintColor } } if currentDate.isToday() && hightlightsToday { @@ -223,7 +225,7 @@ public class EPCalendarPicker: UICollectionViewController { if startDate != nil { if NSCalendar.currentCalendar().startOfDayForDate(cell.currentDate) < NSCalendar.currentCalendar().startOfDayForDate(startDate!) { cell.isCellSelectable = false - cell.lblDay.textColor = EPColors.LightGrayColor + cell.lblDay.textColor = self.dayDisabledTintColor } } } @@ -236,9 +238,8 @@ public class EPCalendarPicker: UICollectionViewController { if hideDaysFromOtherMonth { cell.lblDay.textColor = UIColor.clearColor() } else { - cell.lblDay.textColor = EPColors.LightGrayColor + cell.lblDay.textColor = self.dayDisabledTintColor } -// cell.lblDay.layer.backgroundColor = UIColor.whiteColor().CGColor } cell.backgroundColor = UIColor.clearColor() diff --git a/EPCalendar/ViewController.swift b/EPCalendar/ViewController.swift index 4d7fca6..083368b 100644 --- a/EPCalendar/ViewController.swift +++ b/EPCalendar/ViewController.swift @@ -32,9 +32,10 @@ class ViewController: UIViewController, EPCalendarPickerDelegate { 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.backgroundImage = UIImage(named: "background_image") // calendarPicker.backgroundColor = UIColor.blueColor() let navigationController = UINavigationController(rootViewController: calendarPicker)