Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import JTAppleCalendar
- class KalendarViewController: UIViewController, JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {
- func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
- // The code here is the same as cellForItem function
- let cell = cell as! CalendarCell
- cell.dateLabel.text = cellState.text
- handleCellSelected(cell: cell, cellState: cellState)
- }
- func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
- let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "calenderCell", for: indexPath) as! CalendarCell
- cell.dateLabel.text = cellState.text
- handleCellSelected(cell: cell, cellState: cellState)
- return cell
- }
- func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
- print(cellState.dateBelongsTo)
- handleCellSelected(cell: cell, cellState: cellState)
- }
- func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
- handleCellSelected(cell: cell, cellState: cellState)
- }
- func handleCellSelected(cell: JTAppleCell?, cellState: CellState){
- guard let validCell = cell as? CalendarCell else { return }
- if cellState.isSelected {
- validCell.selectedView.isHidden = false
- } else {
- validCell.selectedView.isHidden = true
- }
- }
- @IBOutlet weak var calendarView: JTAppleCalendarView!
- let formatter = DateFormatter()
- func setupCalendarView() {
- calendarView.minimumLineSpacing = 0
- calendarView.minimumInteritemSpacing = 0
- calendarView.allowsMultipleSelection = true
- }
- func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
- formatter.dateFormat = "dd/MM/yyyy"
- formatter.timeZone = Calendar.current.timeZone
- formatter.locale = Calendar.current.locale
- let startDate = formatter.date(from: "01/01/2017")
- let endDate = formatter.date(from: "01/01/2019")
- let parameters = ConfigurationParameters(startDate: startDate!, endDate: endDate!)
- return parameters
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view.
- setupCalendarView()
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement