Colander is a customizable UIView subclass that displays a scrolling calendar view.
Because Blue Apron is a food company.
Because "Colander" sounds like "calendar", sort of.
Because "CalendarView" was taken.
Colander is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Colander"
// 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()
}
}
A collection view that displays a calendar. Supported functionality:
-
func select(date: Date)
: Selects the cell corresponding theday
component providedDate
. -
func select(dates: [Date])
: Callsselect(date:)
on the provided dates. -
func deselect(date: Date)
: Deselects the cell corresponding theday
component providedDate
. -
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.
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
: Iftrue
(the default behavior), the calendar renders every day instartDate
's month. Iffalse
, the earliest date that will be shown is the beginning ofstartDate
's week (i.e., ifstartDate
is in the last week of its month andshowsLeadingWeeks
is false, only the week containingstartDate
will be shown). -
showsTrailingWeeks
: Iftrue
(the default behavior), the calendar renders every day inendDate
's month. Iffalse
, the last date that will be rendered is the end ofendDate
's week. (i.e., ifendDate
is in the first week of its month andshowsTrailingWeeks
is false, only the week containingendDate
will be shown).
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.
To run the example project:
- Clone the repo
- Run
pod install
from the Example directory - Open
CalendarView.xcworkspace
, build, and run
The example project contains three different example uses of the CalendarView:
- Basic: Uses
CalendarDayCell
packaged with Colander and is generally the most minimal use ofCalendarView
possible - Advanced: Uses a custom day cell and header, highlights the day cell for the current day, supports single selection.
- Advanceder: Same as Advanced, but with multiple selection. Also demonstrates usage of
CalendarView
'sselect(date:)
function.
- iOS 8+ (iOS 9 for the example project due to
UIStackView
use) - Xcode 8+
Colander development was made infinitely more pleasant by SwiftDate and SnapKit.
Bryan Oltman, bryan.oltman@blueapron.com
Colander is available under the MIT license. See the LICENSE file for more info.
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.
Copyright (c) 2015 daniele margutti me@danielemargutti.com
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.