Giter Site home page Giter Site logo

ttcalendarpicker's Introduction

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 13.0+
  • Xcode 11.0+
  • Swift 5.0+

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 11+ 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

Type: TTCalendarPicker.CalendarHeightMode
Default: .fixed

  • .fixed:always shows the maximum number of weeks that can occur in a month
  • .dynamic: resizes to the height required to show number of weeks in the visible month.

cellHeightMode

Type: TTCalendarPicker.CellHeightMode
Default: .aspectRatio(0.88)
Either .fixed (rows have a set height) or .aspectRatio (cell height depends on its width).

gridInsets

Type: UIEdgeInsets
Default: UIEdgeInsets(top: 12.0, left: 16.0, bottom: 12.0, right: 16.0)
Insets for the date cell grid

cellSpacingX

Type: CGFloat
Default: 1.0
Space to insert between columns of dates

cellSpacingY

Type: CGFloat
Default: 1.0
Space to insert between rows of dates

monthHeaderHeight:

Type: CGFloat?
Default: nil Height to allocate for an optional monthHeaderView

selectedDates:

Type: [Date]
Default: []
The currently selected dates, at midnight in the calendarPicker's calendar

allowsMultipleSelection

Type: Bool
Default: false
Whether the selecting additional dates should deselect the previously selected one

gridColor

Type: UIColor
Default: .clear
The color of the area defined by cellSpacingX and cellSpacingY

Contributing

All contributions are welcome, with the caveat that this code is being actively used by a production app, and that it is unlikely we will commit a change that we don't intend to use or that won't contribute to the stability of the codebase.

Author

Initial work by Daniel Roth - [email protected],
with ongoing contributions from the entire iOS team here at Thumbtack.

License

TTCalendarPicker is available under the Apache 2.0 license. See the LICENSE file for more info.

ttcalendarpicker's People

Contributors

dwroth avatar ileitch avatar muhieddine-el-kaissi avatar omoralesvivo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

ileitch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.