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 0000000..7c186c7 Binary files /dev/null and b/EPCalendar/Assets.xcassets/background_image.imageset/background_image.jpg differ diff --git a/EPCalendar/EPCalendarPicker/EPCalendarCell1.swift b/EPCalendar/EPCalendarPicker/EPCalendarCell1.swift index 77b3afb..5e585e5 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarCell1.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarCell1.swift @@ -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 } diff --git a/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib b/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib index 10b803c..d0929db 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib +++ b/EPCalendar/EPCalendarPicker/EPCalendarCell1.xib @@ -1,7 +1,7 @@ - + - + @@ -22,7 +22,7 @@ - + diff --git a/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift b/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift index 5c467bb..8adbca5 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift +++ b/EPCalendar/EPCalendarPicker/EPCalendarConstants.swift @@ -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{ 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..f630d86 100644 --- a/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib +++ b/EPCalendar/EPCalendarPicker/EPCalendarHeaderView.xib @@ -1,7 +1,7 @@ - + - + @@ -56,7 +56,7 @@ - + @@ -115,14 +115,14 @@ - - - - - + + + + + + + - - diff --git a/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift b/EPCalendar/EPCalendarPicker/EPCalendarPicker.swift index ee9607d..e071f8c 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,36 +23,57 @@ public class EPCalendarPicker: UICollectionViewController { 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() + } } @@ -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 @@ -129,7 +149,6 @@ public class EPCalendarPicker: UICollectionViewController { self.arrSelectedDates.appendContentsOf(selectedDates!) } super.init(collectionViewLayout: layout) - } @@ -193,12 +212,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 = 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 { @@ -206,9 +235,14 @@ public class EPCalendarPicker: UICollectionViewController { 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 } @@ -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) { @@ -274,7 +309,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..083368b 100644 --- a/EPCalendar/ViewController.swift +++ b/EPCalendar/ViewController.swift @@ -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) }