JTAppleCalendar如何设置当前日期和当前月

时间:2017-08-14 05:49:28

标签: jtapplecalendar

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

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

  1. 设置当月的日历
  2. JTC.scrollToDate(日期())

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

    2. 我是否需要指定或配置此日历支持的年限为100或200年?

    3. 获取JTAppleCalendar

      的引用是否正确?

      @IBOutlet weak var JTC:JTAppleCalendarView!

    4. 请帮助纠正代码。

        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            
      
              }        
      
          }
      

      由于

1 个答案:

答案 0 :(得分:0)

通过在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

}