Swift
Swift

Reputation: 1184

How to show Current Week in JTAppleCalendar in swift

for calendar i am using JTAppleCalendar pod in my project

and i am able to show current month in calendar, but i need to show current week in calendar but how

for current month showing in calendar am using below code

extension ViewController: JTAppleCalendarViewDataSource {

    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy MM dd"
        let startDate =  formatter.date(from: "2010 01 01")!
        let endDate = formatter.date(from: "2050 01 01")!
        return ConfigurationParameters(startDate: startDate, endDate: endDate)
    }

}

extension ViewController: JTAppleCalendarViewDelegate {

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

        self.calendar(calendar, willDisplay: cell, forItemAt: date, cellState: cellState, indexPath: indexPath)

        if testCalendar.isDateInToday(date) {
            cell.dateLabel.textColor = UIColor.blue
            cell.dateLabel.font = UIFont.boldSystemFont(ofSize: 13.0)

        } else {
            testCalendar.isDateInToday(date) == false

        }

        return cell
    }

    func calendar(_ calendar: JTAppleCalendarView, headerViewForDateRange range: (start: Date, end: Date), at indexPath: IndexPath) -> JTAppleCollectionReusableView {

        let header = calendar.dequeueReusableJTAppleSupplementaryView(withReuseIdentifier: "DateHeader", for: indexPath) as! DateHeader
        formatter.dateFormat = "MMM yyyy"

        header.monthTitle.text = formatter.string(from: range.start)
        return header
    }
    
}

0/p:

enter image description here

but i need to show current week in calendar, how?, plz do help

enter image description here

Upvotes: 1

Views: 690

Answers (2)

RTXGamer
RTXGamer

Reputation: 3712

Return '1' for numberOfRows and modify the configureCalendar like this:

extension ViewController: JTAppleCalendarViewDataSource {
    func configureCalendar(_ calendar: JTAppleCalendarView) -> ConfigurationParameters {
        
        let formatter = DateFormatter()
               formatter.dateFormat = "yyyy MM dd"
               let startDate =  formatter.date(from: "2010 01 01")!
               let endDate = formatter.date(from: "2050 01 01")!
        
            return ConfigurationParameters(startDate: startDate,
                                           endDate: endDate,
                                           numberOfRows: 1,
                                           generateInDates: .forFirstMonthOnly,
                                           generateOutDates: .off,
                                           hasStrictBoundaries: false)
    }
}

Upvotes: 1

Vinayak Bhor
Vinayak Bhor

Reputation: 691

Following cocoapod match your requirement : FSCalender

Please try to use below pod in pod file:

use_frameworks!
target '<Your Target Name>' do
pod 'FSCalendar'
end

Upvotes: 1

Related Questions