1

Hi I am newbie to JTAppleCalendar. I need help. I have installed it thru cocoapods and used some of the code as below.

I need help on how to use the basic functions such as:

  1. Set the calendar for the current month

JTC.scrollToDate(Date())

  1. show the current date on the calendar.

  2. Do I need to specify or configure how many years this calendar support like 100 or 200 years?

  3. Is this way correct to get a reference for the JTAppleCalendar

    @IBOutlet weak var JTC: JTAppleCalendarView!

Please help to correct the code.

  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            

        }        

    }

Thanks

MilkBottle
  • 4,242
  • 13
  • 64
  • 146
  • Can you let me know how you found this calendar? I am trying to make finding help easier. All the tutorials for this calendar can be found >> [HERE](https://www.youtube.com/watch?v=wyh_DVFeH_w&list=PLpqJf39XekqyUG7dxcqGO0JNprryysv9Q) << . I thought that it would be easy to find, but it looks like people are still not finding it. So can you let me know how you found this library? The final video in that tutorial list explains every thing you need. – Just a coder Aug 14 '17 at 14:40
  • It is so good to hear your reply. This calendar is so beautiful. First thing 1st, I search in google: ios Swift calendar , swift 3 is there apple calendar ,In YouTube : swift calendar. from these, I know apple has no Calendar like the one you made. But I need some basic func like i mentioned above, can you help? It will be good if you can list some of the basic func in your tutorial as we are very new to the apple calendar concept like how to set it to current date, how many years I need to setUp for calendar as we are so used to some calendar in web. Thanks – MilkBottle Aug 14 '17 at 15:11
  • Thanks for the information. I'll see how i can improve search rankings. I will also improve the tutorials. I relation to what you asked however, the final video is the list explains some of the common functions like showing the current date, creating headers, loading dates from a server etc. If you need a list of all what the calendar is able to do, then look in the `UserInteractionFunctions.swift` file. It has every function can is possible to be done with the calendar. – Just a coder Aug 14 '17 at 15:18
  • In relation to how many years to configure, keep in mind this calendar caches dates, so dont go crazy and create so many that the the load time takes forever. Trust me, neither Apple Store, or your app, or even you might be around in 70+ years . Experiment with how many you can generate before it gets slower. This is the only part of the calendar I wish i can improve on. But the calculations were to difficult for me to create it as non-cached. Maybe someone smarter than I can open a github pull request with the solution. If you need more information, open a github `issue`. I check every2hrs – Just a coder Aug 14 '17 at 15:22

1 Answers1

3

The issue was solved for me by adding three methods in ViewDidLoad and setting start and end dates as follows:

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() ])


}

In Calendar configuration set dates as follows:

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

}
K.Dᴀᴠɪs
  • 9,945
  • 11
  • 33
  • 43
Sean McCue
  • 31
  • 2