This calendar works like the native iOS weekly calendar, it can be scrolled horizontally and vertically, horizontally if the swipe gesture is long scrolls to the next or previous week, if it is short it scrolls to the next or previous day
It's in Swift 5 for iOS 10 or higher
To run the example project, clone the repo, and run pod install from the Example directory first.
SwiftWeeklyCalendar is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftWeeklyCalendar'mmachado53, [email protected]
WeeklyCalendarCollectionView is the base of the calendar and extends of UICollectionView
- customHeightPerHour:CGFloat = -1 (if a different value is not set, it cannot be scrolled vertically)
- dayCellSize:CGSize : is the current size of the cells, width = frame.width / 7, height = customHeightPerHour * 24
CalendarHeaderCollectionView is the view where you can show the days of the week and extends of UICollectionView
CalendarHoursCollectionView is the view where you can show the hours and extends of UICollectionView
CustomViewController.swift
import SwiftWeeklyCalendar
extension CustomViewController : WeeklyCalendarCollectionViewDelegate{
func weeklyCalendarCollectionView(_ collectionView: WeeklyCalendarCollectionView, cellFor date: Date, indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellidentifier", for: indexPath)
// Configure here the cell view for date in WeeklyCalendarCollectionView instance
return cell
}
func weeklyCalendarCollectionView(collectionView: WeeklyCalendarCollectionView, changeWeek dates: [Date]) {
// "dates" its an array with visible dates
// do something when the calendar has changed date
}
func weeklyCalendarCollectionView(collectionView: WeeklyCalendarCollectionView, didSelectItemAt cellState: Date) {
}
}
extension CustomViewController : CalendarHeaderCollectionViewDelegate {
func calendarHeaderCollectionView(_ collectionView: CalendarHeaderCollectionView, cellFor date: Date, indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellidentifier", for: indexPath)
// Configure here the cell view for headers in the CalendarHeaderCollectionView instance
return cell
}
}
extension CustomViewController : CalendarHoursCollectionViewDelegate {
func calendarHoursCollectionView(_ collectionView: CalendarHoursCollectionView, cellFor hour: Int, indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellidentifier", for: indexPath)
// Configure here the cell view for headers in the CalendarHoursCollectionView instance
return cell
}
}soon :)
SwiftWeeklyCalendar is available under the MIT license. See the LICENSE file for more info.

