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

Created on 26 Oct 2017  路  18Comments  路  Source: patchthecode/JTAppleCalendar

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) {
       //configureCell(view: cell, cellState: cellState)



    }

    func calendar(_ calendar: JTAppleCalendarView, cellForItemAt date: Date, cellState: CellState, indexPath: IndexPath) -> JTAppleCell {
        let cell = calendar.dequeueReusableJTAppleCell(withReuseIdentifier: "CalendarCell", for: indexPath) as! CalendarCell

        if cellState.text == "1" {
            cell.dateLabel1.text = cellState.text
            print(cell.dateLabel1.text!)
        } else {
            cell.dateLabel1 .text = cellState.text
            print(cell.dateLabel1.text!)
        }
        return cell
  }
}

All 18 comments

I believe, if you can see any of the videos from @patchthecode then you will not have this question.

Please have a look on his YouTube channel videos.

The one which should help you is here.

@patchthecode has done a great job not just for the calendar but also by providing such videos.

@hemangshah Thank you..but i watched all videos of calendar from patchthecode.

@poojadeshmukh091, Ok, it will not take more then 8 minutes if you recheck the one which I pointed in my previous comment. I have seen the similar video three months back which helped me to create a custom calendar from the scratch. Please have a look one more time. 馃憤

@hemangshah , yeah okay..i will recheck it..still if u have any solution for this please help me.

Sure I can, but your is incomplete. There should methods to use the custom cell and update them as per the requirement.

@hemangshah which methods?

@poojadeshmukh091, please check that video or download the sample code from Github.

okay

@poojadeshmukh091

OK based on your stackoverflow question here, every thing seems ok

https://stackoverflow.com/questions/46904336/i-want-to-create-custom-calendar-so-i-used-jtapplecalendar-and-want-to-display-d?noredirect=1#comment80840913_46904336

The code you posted to stack overflow is very small.
Can you create a sample project and send it to [email protected] ?

You had said that you do not own the whole project and therefore cannot send the whole code. I understand this. So therefore, can you send me a sample project with that code you have posted?
Since the code you have is still small, it will be easy to see why your labels are not showing up.

Also, another suggestion is to debug the view hierarchy in XCode. I believe you know how to do this as you have mentioned it on the stackoverflow question. Can you tell me if a UILabel exists on your cell? You may not be able to visually see it on the view, but you will be able to see it if you expand the Cell objects located on the left menu of XCode. Expand the cell -> then click on the label -> then look at the position/frame of the label and tell me what it is.

@patchthecode as u said i saw view hierarchy in XCode. I have seen exactly as per u mentioned that label is not visible visually but it is there in left menu in cell menu, but when i click on label it shows(highlights) nothing visually, i will create and mail u my sample project.

@poojadeshmukh091 will await you sample project

@hemangshah i have used methods of delegate and datasource

@patchthecode shared my sample project with u through mail, please check

@patchthecode any suggestions?

The problem was with your constraints.
You did not center your label in the middle of the cell with proper constraints.
Therefore when you run your project, you do not see the label.

The huge sign that this is the problem is the constraint error messages that you see when you run your app. The fix is simple: set your label to be centered inside the cell vertically and horizontally. Then every thing will be displayed ok.

Closing this issue.
Let me know if still stuck.

This may help you to trace out the autolayout constraint errors:

https://www.wtfautolayout.com/

@hemangshah @patchthecode The videos are unavailable on Youtube. Is there any other link to it?

@MamtaKukreja vids were removed because this lib is constantly being updated.
but the video cannot be updated.

full tutorials can be found here instead https://patchthecode.com/jtapplecalendar-home/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhanswift picture zhanswift  路  5Comments

gotamafandy picture gotamafandy  路  3Comments

prahaladm picture prahaladm  路  3Comments

programus picture programus  路  3Comments

oddpandadesign picture oddpandadesign  路  5Comments