- April 27, 2024
- Mins Read
CalendarKit is a Swift calendar UI library for iOS and Mac Catalyst. It looks similar to the Apple Calendar app out-of-the-box, while allowing customization when needed. CalendarKit is composed of multiple modules which can be used together or independently.
If you have a programming question about how to use CalendarKit in your application, ask it on StackOverflow with the CalendarKit tag. Check out the Sample App for reference.
Please, use GitHub Issues only for reporting a bug or requesting a new feature.
To try CalendarKit with CocoaPods issue the following command in the Terminal:
pod try CalendarKit
CalendarKit can be installed with Swift Package Manager or with CocoaPods.
The preferred way of installing CalendarKit is via the Swift Package Manager.
https://github.com/richardtop/CalendarKit.git
) and click Next.Adding Package Dependencies to Your App
To install it, add the following line to your Podfile:
pod ‘CalendarKit’
Adding Pods to an Xcode project
DayViewController
EventDataSource
protocol to show events.CalendarKit requires EventDataSource
to return an array of objects conforming to EventDescriptor
protocol, specifying all the information needed to display a particular event. You’re free to use a default Event
class as a model or create your own class conforming to the EventDescriptor
protocol.
// Return an array of EventDescriptors for particular date
override func eventsForDate(_ date: Date) -> [EventDescriptor] {
var models = myAppEventStore.getEventsForDate(date) // Get events (models) from the storage / API
var events = [Event]()
for model in models {
// Create new EventView
let event = Event()
// Specify DateInterval
event.dateInterval = DateInterval(start: model.startDate, end: model.endDate)
// Add info: event title, subtitle, location to the array of Strings
var info = [model.title, model.location]
info.append(“\(datePeriod.beginning!.format(with: “HH:mm”)) – \(datePeriod.end!.format(with: “HH:mm”))”)
// Set “text” value of event by formatting all the information needed for display
event.text = info.reduce(“”, {$0 + $1 + “\n”})
events.append(event)
}
return events
}
After receiving an array of events for a particular day, CalendarKit will handle view layout and display.
To respond to the user input, override mehtods of DayViewDelegate
, for example:
override func dayViewDidSelectEventView(_ eventView: EventView) {
print(“Event has been selected: \(eventview.data)”)
}
override func dayViewDidLongPressEventView(_ eventView: EventView) {
print(“Event has been longPressed: \(eventView.data)”)
}
CalendarKit supports localization and uses iOS default locale to display month and day names. First day of the week is also selected according to the iOS locale.
By default, CalendarKit looks similar to the Apple Calendar app and fully supports Dark Mode. If needed, CalendarKit’s look can be easily customized. Steps to apply a custom style are as follows:
CalendarStyle
object (or copy existing one)updateStyle
method with the new CalendarStyle
.
let style = CalendarStyle()
style.backgroundColor = UIColor.black
dayView.updateStyle(style)
Horizon SDK is a state of the art real-time video recording / photo shooting iOS library. Some of the features ...