An iOS calendar library for displaying calendar events in a week view.
- See calendar events in a week view
- Asynchronously load calendar events
- Interaction with specific events by clicking
- Interaction with free time spaces by clicking
- Custom styling
- Infinite horizontal scrolling
- Using TimelineCollectionView as a foundation over a custom UIScrollView for improved stability
- Improved display of events that overlap
- Improved handling of asynchronously-fetched data
- Bug fixes
Download Source
files and install dependencies
Implement the weekViewGenerateEvents
protocol function. This function should return a list of WeekViewEvent
s specific to the day of date
. Events that can be created immediately should be returned to this function. Events that require time to create should be passed to eventCompletion
, which will overwrite previously returned events. See here for SwiftDate documentation on creating date objects at specific times. Currently, events rely on a 24-hour clock.
func weekViewGenerateEvents(_ weekView: WeekView, date: DateInRegion, eventCompletion: @escaping ([WeekViewEvent]?) -> Void) -> [WeekViewEvent]? {
let start: DateInRegion = date.dateBySet(hour: 12, min: 0, secs: 0)!
let end: DateInRegion = date.dateBySet(hour: 13, min: 0, secs: 0)!
let event: WeekViewEvent = WeekViewEvent(title: "Lunch", start: start, end: end)
DispatchQueue.global(.background).async {
// do some async work & create events...
eventCompletion([event, ...])
}
return [event]
}
title
: the title of the eventsubtitle
: a subtitle or description of the eventstart
: the start time of the eventend
: the end time of the event
Create an instance of WeekView
, specify it's data source, and add it as a subview.
let weekView = WeekView(frame: frame, visibleDays: 5)
weekView.dataSource = self
addSubview(weekView)
frame
: the frame of the calendar viewvisibleDays
: amount of days that are visible on one page. Default = 5date
: (Optional) the dayWeekView
will initially load. Default = today
Add a view to the storyboard and set it's class WeekView
. Assign the view's data source programmatically.
@IBOutlet weak var weekView: WeekView!
weekView.dataSource = self
To handle interaction with WeekView
, implement the WeekViewDelegate
protocol and set the delegate
property to the implementing class.
// Fires when a calendar event is touched on
func weekViewDidClickOnEvent(_ weekView: WeekView, event: WeekViewEvent, view: UIView)
// Fires when a space without an event is tapped
func weekViewDidClickOnFreeTime(_ weekView: WeekView, date: DateInRegion)
To use custom styling, implement the WeekViewStyler
protocol and assign the styler
property to the implementing class. WeekView
by default is its own styler.
// Creates the view for an event
func weekViewStylerEventView(_ weekView: WeekView, eventContainer: CGRect, event: WeekViewEvent) -> UIView
// Create the header view for the day in the calendar. This would normally contain information about the date
func weekViewStylerHeaderView(_ weekView: WeekView, with date: DateInRegion, in cell: UICollectionViewCell) -> UIView
Included in Source
as a framework. Make sure to add TimelineCollectionView.framework
to your target's Embedded binaries
.
Currently, SwiftDate versions 5.0.x are supported
pod 'SwiftDate', '~> 5.0'
See the included example for basic implementation. Make sure to download the entire repository, and then open the .xcworkspace
for it to work properly with the Source files and CocoaPods.