简体   繁体   中英

I want to create custom calendar so i used JTAppleCalendar and want to display date in collection view cell

I want to create custom calendar so I used JTAppleCalendar for this I have taken one collection view and want to display date in collection view cell but it is not displaying what should be the solution for this?

CalendarViewController.swift

import UIKit
import JTAppleCalendar

class CalendarViewController: UIViewController {

    @IBOutlet weak var calendarView: JTAppleCalendarView!

    override func viewDidLoad() {
        super.viewDidLoad()

       self.calendarView.calendarDataSource = self
        self.calendarView.calendarDelegate = self
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension CalendarViewController:JTAppleCalendarViewDelegate,JTAppleCalendarViewDataSource{

    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {

        let formatter = DateFormatter()

        formatter.dateFormat = "yyyy MM dd"
        formatter.timeZone = Calendar.current.timeZone
        formatter.locale = Calendar.current.locale

        let startdate = formatter.date(from: "2017 01 01")!
        let enddate = formatter.date(from: "2017 12 31")!
        let parameters = ConfigurationParameters(startDate: startdate, endDate: enddate)
      // print(formatter.string(from: startdate))
        return parameters
    }

    func calendar(_ calendar: JTAppleCalendarView, willDisplay cell: JTAppleCell, forItemAt date: Date, cellState: CellState, indexPath: IndexPath) {

    }

    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {

        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CalendarCell", for: indexPath) as! CalendarCell

        cell.dateLabel.text = cellState.text

        return cell
    }
}



CalendarCell.swift

import UIKit
import JTAppleCalendar
class CalendarCell: JTAppleCell {


    @IBOutlet weak var dateLabel: UILabel!
}
calendarView.registerCellViewXib(file: "CalendarDateCell")
calendarView.delegate = self
calendarView.dataSource = self
calendarView.direction = .horizontal
calendarView.selectDates([selectedDate])
calendarView.reloadData()

add in viewdidLoad()

在此处输入图片说明

your xib will be look like above image and take a outlet like below ignore arrow Img, Wrapper View

    import UIKit
import JTAppleCalendar

class CalendarDateCell: JTAppleDayCellView {

    @IBOutlet weak var dateLbl: UILabel!
    @IBOutlet weak var wrapperView: UIView!
    @IBOutlet weak var arrowImg: UIImageView!
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM