Skip to content

A highly customizable iOS calendar view

License

Notifications You must be signed in to change notification settings

blueapron/Colander

Repository files navigation

Colander

Colander

CI Status Version License Platform

Colander is a customizable UIView subclass that displays a scrolling calendar view.

Why "Colander"?

Because Blue Apron is a food company.

Because "Colander" sounds like "calendar", sort of.

Because "CalendarView" was taken.

Installation

Colander is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "Colander"

Usage

    // In YourViewController.swift...
    override func viewDidLoad() {
        let calendarView = CalendarView()

        // Optional (but probably something you'll want to do): register cell and header types
        // NOTE: both of these must conform to the Dated protcol, which mandates they have a Date? var with public get and set
        calendarView.register(cellType: YourDayCellClass.self)
        calendarView.register(supplementaryViewType: YourHeaderViewClass.self, ofKind: UICollectionElementKindSectionHeader)

        // Wire up datasource and delegate
        calendarView.dataSource = self
        calendarView.delegate = self
        view.addSubview(calendarView)

        // Assuming you're using SnapKit...
        calendarView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }

CalendarView

A collection view that displays a calendar. Supported functionality:

  • func select(date: Date): Selects the cell corresponding the day component provided Date.

  • func select(dates: [Date]): Calls select(date:) on the provided dates.

  • func deselect(date: Date): Deselects the cell corresponding the day component provided Date.

  • var selectedDates: [Date]: A read-only array of all the currently selected dates.

  • func select(cellAt indexPath: IndexPath): Selects the cell at the provided index path.

  • func deselect(cellAt indexPath: IndexPath): Deselects the cell at the provided index path.

CalendarViewDataSource

There are only two functions required by the data source: startDate and endDate. These functions represent the range of time displayed by the CalendarView.

CalendarViewDataSource also has a few optional properties:

  • calendar: The calendar you wish to display. This property defaults to the Gregorian calendar.

  • showsLeadingWeeks: If true (the default behavior), the calendar renders every day in startDate's month. If false, the earliest date that will be shown is the beginning of startDate's week (i.e., if startDate is in the last week of its month and showsLeadingWeeks is false, only the week containing startDate will be shown).

  • showsTrailingWeeks: If true (the default behavior), the calendar renders every day in endDate's month. If false, the last date that will be rendered is the end of endDate's week. (i.e., if endDate is in the first week of its month and showsTrailingWeeks is false, only the week containing endDate will be shown).

CalendarViewDelegate

As with UITableViewDelegate and UICollectionViewDelegate, adding support for the CalendarViewDelegate protocol is entirely optional. These functions simply forward/wrap UICollectionViewDelegate functions on the underlying UICollectionView and have the same semantics.

Example

To run the example project:

  1. Clone the repo
  2. Run pod install from the Example directory
  3. Open CalendarView.xcworkspace, build, and run

The example project contains three different example uses of the CalendarView:

  1. Basic: Uses CalendarDayCell packaged with Colander and is generally the most minimal use of CalendarView possible
  2. Advanced: Uses a custom day cell and header, highlights the day cell for the current day, supports single selection.
  3. Advanceder: Same as Advanced, but with multiple selection. Also demonstrates usage of CalendarView's select(date:) function.

Requirements

  • iOS 8+ (iOS 9 for the example project due to UIStackView use)
  • Xcode 8+

Dependencies

Colander development was made infinitely more pleasant by SwiftDate and SnapKit.

Author

Bryan Oltman, [email protected]

License

Colander is available under the MIT license. See the LICENSE file for more info.

Third-Party Licenses

SnapKit

Copyright (c) 2011-Present SnapKit Team - https://github.com/SnapKit

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

SwiftDate

Copyright (c) 2015 daniele margutti [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.