- Welcome
- Getting started
- Latest updates
- Foundations
-
Components
- Accordion
- Alert
- Alignment
- App Search Modal
- Aria live
- Autosuggest
- Badge
- Banner alert
- Bar chart
- Blockquote
- Bottom navigation
- Bottom sheet
- Breadcrumb
- Breakpoint
- Button
- Calendar
- Card
- Card list
- Card button
- Carousel
- Checkbox
- Chip
- Chip group
- Code
- Content cards
- Data Table
- Datepicker
- Description list
- Dialog
- Divider
- Drawer
- Field Set
- Flare
- Flat list
- Flight leg
- Floating action button
- Floating notification
- Form label
- Form validation
- Graphic promotion
- Horizontal navigation
- Icon
- Image
- Image Gallery
- Infinite scroll
- Info Banner
- Inset Banner
- Link
- List
- Map
- Mobile scroll container
- Modal
- Navigation bar
- Navigation Tab Group
- Nudger
- Overlay
- Page indicator
- Pagination
- Panel
- Phone input
- Picker
- Popover
- Price
- Progress bar
- Radio button
- Rating
- Rating Bar
- Scrollable calendar
- Search Modal
- Section header
- Section list
- Select
- Skeleton
- Skip link
- Slider
- Snackbar
- Snippet
- Spinner
- Split input
- Star rating
- Swap Button
- Switch
- Table
- Text
- Text input
- Theming
- Ticket
- Toast
- Tooltip
- Touchable native feedback
- Touchable overlay
- Search Input Summary
- Content
- Accessibility
- Contributing
- Localisation
Calendar
Calendars are used for date selection within a defined time period.
Backpack/Calendar
Single date
Day | Night |
---|---|
Date range
Day | Night |
---|---|
Multiple
Day | Night |
---|---|
Custom colours
Day | Night |
---|---|
With prices
Day | Night |
---|---|
Showing year pill
Day | Night |
---|---|
Installation
In Podfile add
pod 'Backpack/Calendar'
and then run pod install.
Usage
Backpack/Calendar contains the Backpack Calendar component in the class BPKCalendar. The calendar is a calendar view offering user interaction.
Simple calendar
Objective-C
#import <Backpack/Calendar.h>
#import <Backpack/SimpleDate.h>
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationSingle alloc] initWithSelectionHint:@"Double tap to select date"];
bpkCalendar.selectedDates = @[[bpkCalendar simpleDateFromDate:self.date1]];
[bpkCalendar reloadData];
// ...
#pragma mark - <BPKCalendarDelegate>
- (void)calendar:(BPKCalendar *)calendar didChangeDateSelection:(NSArray<BPKSimpleDate *> *)dateList {
// do stuff
}
- (void)calendar:(BPKCalendar *)calendar didScroll:(CGPoint)contentOffset {
// do stuff
}
- (BOOL)calendar:(BPKCalendar *)calendar isDateEnabled:(NSDate *)date {
// do stuff
}
Swift
import Backpack
let calendar = BPKCalendar(frame: .zero)
calendar.minDate = calendar.simpleDate(from: Date())
calendar.locale = Locale.current
// ...
extension MyClass: BPKCalendarDelegate {
func calendar(_ calendar: BPKCalendar, didChangeDateSelection dateList: [BPKSimpleDate]) {
// do stuff
}
func calendar(_ calendar: BPKCalendar, didScroll contentOffset: CGPoint) {
// do stuff
}
func calendar(_ calendar: BPKCalendar, isDateEnabled: Date) -> Bool {
// do stuff
}
}
Color-coded calendar
A colour coded calendar where dates are coloured based on how expensive/cheap they are.
Objective-C
#import <Backpack/Calendar.h>
#import <Backpack/SimpleDate.h>
NSSet<BPKSimpleDate *> *lowPrices = /* .... */;
NSSet<BPKSimpleDate *> *mediumPrices = /* .... */;
NSSet<BPKSimpleDate *> *highPrices = /* .... */;
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithFrame:CGRectZero];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationSingle alloc] initWithSelectionHint:@"Double tap to select date"];
bpkCalendar.selectedDates = @[[bpkCalendar simpleDateFromDate:self.date1]];
[bpkCalendar reloadData];
// ...
#pragma mark - <BPKCalendarDelegate>
- (id _Nullable)calendar:(BPKCalendar *)calendar cellDataForDate:(BPKSimpleDate *)date {
if ([lowPrices containsObject:date) {
return BPKCalendarTrafficLightCellData.positive;
}
if ([mediumPrices containsObject:date) {
return BPKCalendarTrafficLightCellData.neutral;
}
if ([highPrices containsObject:date) {
return BPKCalendarTrafficLightCellData.negative;
}
return BPKCalendarTrafficLightCellData.normal;
}
- (void)calendar:(BPKCalendar *)calendar didChangeDateSelection:(NSArray<BPKSimpleDate *> *)dateList {
// do stuff
}
Swift
import Backpack
let lowPrices: Set<BPKSimpleDate> = ...
let mediumPrices: Set<BPKSimpleDate> = ...
let highPrices: Set<BPKSimpleDate> = ...
let calendar = BPKCalendar(frame: .zero)
calendar.minDate = calendar.simpleDate(from: Date())
calendar.locale = Locale.current
// ...
extension MyClass: BPKCalendarDelegate {
func calendar(_ calendar: BPKCalendar, cellDataFor date: BPKSimpleDate) -> Any? {
if lowPrices.contains(date) {
return BPKCalendarTrafficLightCellData.positive
}
if mediumPrices.contains(date) {
return BPKCalendarTrafficLightCellData.neutral
}
if highPrices.contains(date) {
return BPKCalendarTrafficLightCellData.negative
}
return BPKCalendarTrafficLightCellData.normal
}
}
func calendar(_ calendar: BPKCalendar, didChangeDateSelection dateList: [BPKSimpleDate]) {
// do stuff
}
}
Priced calendar
A calendar where cells display a price.
Objective-C
#import <Backpack/Calendar.h>
#import <Backpack/SimpleDate.h>
NSSet<BPKSimpleDate *> *lowPrices = /* .... */;
NSSet<BPKSimpleDate *> *mediumPrices = /* .... */;
NSSet<BPKSimpleDate *> *highPrices = /* .... */;
BPKCalendar *bpkCalendar = [[BPKCalendar alloc] initWithConfiguration: [BPKCalendarPriceLabelConfiguration new]];
bpkCalendar.selectionConfiguration = [[BPKCalendarSelectionConfigurationSingle alloc] initWithSelectionHint:@"Double tap to select date"];
bpkCalendar.selectedDates = @[[bpkCalendar simpleDateFromDate:self.date1]];
[bpkCalendar reloadData];
// ...
#pragma mark - <BPKCalendarDelegate>
- (id _Nullable)calendar:(BPKCalendar *)calendar cellDataForDate:(BPKSimpleDate *)date {
if ([lowPrices containsObject:date) {
return [[BPKCalendarPriceLabelCellData alloc] initWithPrice: @"£12" labelStyle: BPKCalendarPriceLabelStyle.positive];
}
if ([mediumPrices containsObject:date) {
return [[BPKCalendarPriceLabelCellData alloc] initWithPrice: @"£25" labelStyle: BPKCalendarPriceLabelStyle.neutral];
}
if ([highPrices containsObject:date) {
return [[BPKCalendarPriceLabelCellData alloc] initWithPrice: @"£43" labelStyle: BPKCalendarPriceLabelStyle.negative];
}
return [[BPKCalendarPriceLabelCellData alloc] initWithPrice: @"-" labelStyle: BPKCalendarPriceLabelStyle.noData];
}
- (void)calendar:(BPKCalendar *)calendar didChangeDateSelection:(NSArray<BPKSimpleDate *> *)dateList {
// do stuff
}
Swift
import Backpack
let lowPrices: Set<BPKSimpleDate> = ...
let mediumPrices: Set<BPKSimpleDate> = ...
let highPrices: Set<BPKSimpleDate> = ...
let calendar = BPKCalendar(configuration: BPKCalendarPriceLabelConfiguration())
calendar.minDate = calendar.simpleDate(from: Date())
calendar.locale = Locale.current
// ...
extension MyClass: BPKCalendarDelegate {
func calendar(_ calendar: BPKCalendar, cellDataFor date: BPKSimpleDate) -> Any? {
if lowPrices.contains(date) {
return BPKCalendarPriceLabelCellData(price: "£12", labelStyle: BPKCalendarPriceLabelStyle.positive)
}
if mediumPrices.contains(date) {
return BPKCalendarPriceLabelCellData(price: "£25", labelStyle: BPKCalendarPriceLabelStyle.neutral)
}
if highPrices.contains(date) {
return BPKCalendarPriceLabelCellData(price: "£43", labelStyle: BPKCalendarPriceLabelStyle.negative)
}
return BPKCalendarPriceLabelCellData(price: "-", labelStyle: BPKCalendarPriceLabelStyle.noData)
}
}
func calendar(_ calendar: BPKCalendar, didChangeDateSelection dateList: [BPKSimpleDate]) {
// do stuff
}
}
Whole month selection
You can enable the selection of an entire month by setting the wholeMonthSelectionConfiguration on the BPKCalendar. The selectableMonthRange can be nil, which will not disable any selection options.
Keep in mind that when you set a min and max date on the calendar, you want to match this in your whole month configuration.
There are no safeguards in place to disable whole month for months that are fully disabled.
let calendar = BPKCalendar()
/* code omitted */
calendar.wholeMonthSelectionConfiguration = BPKCalendarWholeMonthConfiguration(
title: "Select whole month",
selectableMonthRange: BPKYearMonth(year: 2020, month: 1)...BPKYearMonth(year: 2020, month: 12)
)
Appearance attributes
- (UIColor)dateSelectedContentColor
- (UIColor)dateSelectedBackgroundColor
Made with ❤️ by Skyscanner © 2024
© 2024 Skyscanner Backpack. Page last updated on Nov 22, 2023, 11:03