80 lines
2.9 KiB
Swift
80 lines
2.9 KiB
Swift
//
|
|
// ViewController.swift
|
|
// SwiftExample
|
|
//
|
|
// Created by Wenchao Ding on 9/3/15.
|
|
// Copyright (c) 2015 wenchao. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class InterfaceBuilderViewController: UIViewController, FSCalendarDataSource, FSCalendarDelegate {
|
|
|
|
@IBOutlet weak var calendar: FSCalendar!
|
|
@IBOutlet weak var calendarHeightConstraint: NSLayoutConstraint!
|
|
|
|
private let formatter: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.dateFormat = "yyyy/MM/dd"
|
|
return formatter
|
|
}()
|
|
private let gregorian: NSCalendar! = NSCalendar(calendarIdentifier:NSCalendar.Identifier.gregorian)
|
|
|
|
let datesWithCat = ["2015/05/05","2015/06/05","2015/07/05","2015/08/05","2015/09/05","2015/10/05","2015/11/05","2015/12/05","2016/01/06",
|
|
"2016/02/06","2016/03/06","2016/04/06","2016/05/06","2016/06/06","2016/07/06"]
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.calendar.appearance.caseOptions = [.headerUsesUpperCase,.weekdayUsesUpperCase]
|
|
self.calendar.select(self.formatter.date(from: "2015/10/10")!)
|
|
// self.calendar.scope = .week
|
|
self.calendar.scopeGesture.isEnabled = true
|
|
// calendar.allowsMultipleSelection = true
|
|
|
|
// Uncomment this to test month->week and week->month transition
|
|
/*
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(2.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
|
|
self.calendar.setScope(.Week, animated: true)
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(1.5 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) { () -> Void in
|
|
self.calendar.setScope(.Month, animated: true)
|
|
}
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
func minimumDate(for calendar: FSCalendar) -> Date {
|
|
return self.formatter.date(from: "2015/01/01")!
|
|
}
|
|
|
|
func maximumDate(for calendar: FSCalendar) -> Date {
|
|
return self.formatter.date(from: "2016/10/31")!
|
|
}
|
|
|
|
func calendar(_ calendar: FSCalendar, numberOfEventsFor date: Date) -> Int {
|
|
let day: Int! = self.gregorian.component(.day, from: date)
|
|
return day % 5 == 0 ? day/5 : 0;
|
|
}
|
|
|
|
func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
|
|
NSLog("change page to \(self.formatter.string(from: calendar.currentPage))")
|
|
}
|
|
|
|
func calendar(_ calendar: FSCalendar, didSelect date: Date) {
|
|
NSLog("calendar did select date \(self.formatter.string(from: date))")
|
|
}
|
|
|
|
func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) {
|
|
calendarHeightConstraint.constant = bounds.height
|
|
view.layoutIfNeeded()
|
|
}
|
|
|
|
func calendar(_ calendar: FSCalendar, imageFor date: Date) -> UIImage? {
|
|
let day: Int! = self.gregorian.component(.day, from: date)
|
|
return [13,24].contains(day) ? UIImage(named: "icon_cat") : nil
|
|
}
|
|
|
|
}
|
|
|