I'm using a cocoapods named JTAppleCalendar.
I encountered a situation where I can only select dates with two fingers touching the screen at the same time. I've to unchecked 'Multiple Touch' in Xcode, and also tried programmatically disabling multiple touch, but the problem remains. I would appreciate if anyone can help me with this.
Here's the code:
override func viewDidLoad() {
super.viewDidLoad()
setupCalendarView()
self.calendarView.isMultipleTouchEnabled = false
}
func setupCalendarView(){
calendarView.minimumLineSpacing = 0
calendarView.minimumInteritemSpacing = 0
calendarView.visibleDates{ (visibleDates) in
self.setupViewofCalendar(from: visibleDates)
}
}
func setupViewofCalendar(from visibleDates: DateSegmentInfo){
let date = visibleDates.monthDates.first!.date
self.formatter.dateFormat = "yyyy"
self.year.text = self.formatter.string(from:date)
self.formatter.dateFormat = "MMMM"
self.month.text = self.formatter.string(from:date)
}
func handleCellTextColor(view: JTAppleCell?, cellState: CellState) {
guard let validCell = view as? CalendarCustomCell else { return }
if cellState.isSelected {
validCell.dateLabel.textColor = selectedMonthColor
validCell.selectedView.isHidden = false
} else {
if cellState.dateBelongsTo == .thisMonth{
validCell.dateLabel.textColor = UIColor.black
}
else{
validCell.dateLabel.textColor = outsideMonthColor
}
validCell.selectedView.isHidden = false
}
}
func handleCellSeleted(view: JTAppleCell?, cellState: CellState) {
guard let validCell = view as? CalendarCustomCell else { return }
if validCell.isSelected {
validCell.selectedView.isHidden = false
} else {
validCell.selectedView.isHidden = true
}
}
extension calendarViewController: JTAppleCalendarViewDataSource{
func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
formatter.dateFormat = "yyyy MM dd"
formatter.timeZone = Calendar.current.timeZone
formatter.locale = Calendar.current.locale
let todayDate = Date()
let endDate = Calendar.current.date(byAdding: .month, value: 12, to: Date())
let parameters = ConfigurationParameters(startDate: todayDate, endDate: endDate!)
return parameters
}
}
extension calendarViewController: JTAppleCalendarViewDelegate {
//display cell
func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CustomCell", for: indexPath) as! CalendarCustomCell
cell.dateLabel.text = cellState.text
handleCellTextColor(view: cell, cellState: cellState)
handleCellSeleted(view: cell, cellState: cellState)
return cell
}
func calendar(_ calendar: JTAppleCalendarView, didSelectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
handleCellTextColor(view: cell, cellState: cellState)
handleCellSeleted(view: cell, cellState: cellState)
}
func calendar(_ calendar: JTAppleCalendarView, didDeselectDate date: Date, cell: JTAppleCell?, cellState: CellState) {
handleCellTextColor(view: cell, cellState: cellState)
handleCellSeleted(view: cell, cellState: cellState)
}
func calendar(_ calendar: JTAppleCalendarView, didScrollToDateSegmentWith visibleDates: DateSegmentInfo) {
setupViewofCalendar(from: visibleDates)
}
}