Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. import UIKit
  2. import JTAppleCalendar
  3.  
  4. class KalendarViewController: UIViewController, JTAppleCalendarViewDelegate, JTAppleCalendarViewDataSource {
  5.  
  6. func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {
  7. // The code here is the same as cellForItem function
  8. let cell = cell as! CalendarCell
  9. cell.dateLabel.text = cellState.text
  10.  
  11. handleCellSelected(cell: cell, cellState: cellState)
  12. }
  13.  
  14. func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
  15. let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "calenderCell", for: indexPath) as! CalendarCell
  16. cell.dateLabel.text = cellState.text
  17.  
  18. handleCellSelected(cell: cell, cellState: cellState)
  19.  
  20. return cell
  21. }
  22.  
  23.  
  24. func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
  25. print(cellState.dateBelongsTo)
  26. handleCellSelected(cell: cell, cellState: cellState)
  27. }
  28.  
  29. func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
  30. handleCellSelected(cell: cell, cellState: cellState)
  31. }
  32.  
  33.  
  34. func handleCellSelected(cell: JTAppleCell?, cellState: CellState){
  35. guard let validCell = cell as? CalendarCell else { return }
  36. if cellState.isSelected {
  37. validCell.selectedView.isHidden = false
  38. } else {
  39. validCell.selectedView.isHidden = true
  40. }
  41. }
  42.  
  43. @IBOutlet weak var calendarView: JTAppleCalendarView!
  44.  
  45. let formatter = DateFormatter()
  46.  
  47. func setupCalendarView() {
  48. calendarView.minimumLineSpacing = 0
  49. calendarView.minimumInteritemSpacing = 0
  50. calendarView.allowsMultipleSelection = true
  51. }
  52.  
  53. func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
  54. formatter.dateFormat = "dd/MM/yyyy"
  55. formatter.timeZone = Calendar.current.timeZone
  56. formatter.locale = Calendar.current.locale
  57.  
  58. let startDate = formatter.date(from: "01/01/2017")
  59. let endDate = formatter.date(from: "01/01/2019")
  60.  
  61. let parameters = ConfigurationParameters(startDate: startDate!, endDate: endDate!)
  62. return parameters
  63. }
  64.  
  65.  
  66. override func viewDidLoad() {
  67. super.viewDidLoad()
  68.  
  69. // Do any additional setup after loading the view.
  70.  
  71. setupCalendarView()
  72. }
  73.  
  74.  
  75.  
  76. override func didReceiveMemoryWarning() {
  77. super.didReceiveMemoryWarning()
  78. // Dispose of any resources that can be recreated.
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement