Skip to content

A lightweight, highly customizable, infinite scrolling calendar picker developed by the iOS teams at Thumbtack

License

Notifications You must be signed in to change notification settings

thumbtack/TTCalendarPicker

Repository files navigation

TTCalendarPicker

TTCalendarPicker is a lightweight, highly configurable, infinite scrolling calendar picker view. TTCalendarPicker was developed by the iOS teams at Thumbtack, Inc and currently drives our styled calendar picker. While we are unlikely to add requested features that we don't plan on using within our own apps, we will be actively fixing bugs as they are found.

Example

To run the example project, clone the repo then build and run the TTCalendarPicker-Example project.

Requirements

  • iOS 16.0+
  • Xcode 16.0+
  • Swift 5.10+

Installation

Swift Package Manager

Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

Xcode 16+ is required to build TTCalendarPicker using Swift Package Manager.

To integrate TTCalendarPicker into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift:

dependencies: [
    .package(url: "https://github.com/thumbtack/TTCalendarPicker.git", .upToNextMajor(from: "0.2.0"))
]

Usage

Basic Calendar

At a bare minimum, to use TTCalendarPicker you must:

  1. Instantiate a TTCalendarPicker.CalendarPicker object. By deafult, the CalendarPicker will use the user's current, locale based calendar.
  2. Constrain the calendar so that it has an unambiguous width. The calendar will constrain it's own height based on it's width, its calendarHeightMode, and it's cellHeightMode.
  3. Provide the calendarPicker with a dataSource object, and register a dateCell class/nib, e.g.:
    calendarPicker.registerDateCell(DateCell.self, withReuseIdentifier: "DateCell")
  4. In the calendarPicker data source, deque and configure a cell for the given date, e.g.:
    func calendarPicker(_ calendarPicker: CalendarPicker, cellForDay day: Int,
                        month: Int, year: Int, inVisibleMonth: Bool, at indexPath: IndexPath) -> UICollectionViewCell {
        let cell = calendarPicker.dequeReusableDateCell(
            withReuseIdentifier: "DateCell",
            indexPath: indexPath)
            as! DateCell
        cell.setText("\(day)")
        cell.isInVisibleMonth = inVisibleMonth
        return cell
    }

Configuring the Calendar

TTCalendarPicker is highly configurable. Since the date cells and month headers are provided by the devloper, it can support nearly any design you can think of. Additionally, TTCalendarPicker supports the following configuration properties

previousMonthCount

Type: Int
Default: nil
The number of months, before the initial month, that the user should be able to scroll to.

additionalMonthCount

Type: Int
Default: nil
The number of months, ater the initial month, that the user should be able to scroll to.

calendarHeightMode