1

嗨,我是 JTAppleCalendar 的新手。我需要帮助。我已经通过 cocoapods 安装了它,并使用了如下的一些代码。

我需要有关如何使用基本功能的帮助,例如:

  1. 设置当前月份的日历

JTC.scrollToDate(日期())

  1. 在日历上显示当前日期。

  2. 我是否需要指定或配置此日历支持多少年,例如 100 年或 200 年?

  3. 获取 JTAppleCalendar 参考的这种方式是否正确

    @IBOutlet 弱变量 JTC:JTAppleCalendarView!

请帮助更正代码。

  import UIKit
    import JTAppleCalendar


    class ViewController: UIViewController {

        let formatter = DateFormatter()

        @IBOutlet weak var JTC: JTAppleCalendarView!


        override func viewDidLoad() {
            super.viewDidLoad()

        let d = Date()        
        var dateArr = [Date]()        
        dateArr.append(d)

     JTC.scrollToDate(Date())


        }

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

    extension ViewController: JTAppleCalendarViewDelegate,JTAppleCalendarViewDataSource{

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

            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: "2117 12 31")!


            let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate)

            return parameters


        }

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

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

            cell.dateLabel.text = cellState.text

            return cell            

        }        

    }

谢谢

4

1 回答 1

3

通过在 ViewDidLoad 中添加三个方法并设置开始和结束日期,我解决了这个问题,如下所示:

override func viewDidLoad()  {

    self.calendarView.visibleDates {[unowned self] (visibleDates: DateSegmentInfo) in
        self.setupViewsOfCalendar(from: visibleDates)
    }

    self.calendarView.scrollToDate(Date(),animateScroll: false)
    self.calendarView.selectDates([ Date() ])


}

在日历配置中设置日期如下:

func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
    formatter.dateFormat = "yyy MM dd"
    formatter.timeZone = Calendar.current.timeZone
    formatter.locale = Calendar.current.locale

    var dateComponent = DateComponents()
    dateComponent.year = 1
    let startDate = Date()
    let endDate = Calendar.current.date(byAdding: dateComponent, to: startDate)
    let parameters = ConfigurationParameters(startDate: startDate, endDate: endDate!, numberOfRows: 6, calendar: Calendar.current, generateInDates: .forFirstMonthOnly, generateOutDates: .off, firstDayOfWeek: .sunday, hasStrictBoundaries: true)


    return parameters

}
于 2018-03-30T22:40:01.177 回答