![CalendarKit](https://user-images.githubusercontent.com/8013017/146282209-191d8550-3cfa-45f5-bd82-6a9d2b53bc6f.png#gh-dark-mode-only) ![CalendarKit](https://user-images.githubusercontent.com/8013017/146282215-41e228cc-2724-4722-ba16-3126c47730c8.png#gh-light-mode-only) [![License](https://img.shields.io/github/license/richardtop/calendarkit)](https://swiftpackageindex.com/richardtop/CalendarKit) [![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-orange.svg)](https://swiftpackageindex.com/richardtop/CalendarKit) [![Swift Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardtop%2FCalendarKit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/richardtop/CalendarKit) [![Platform Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Frichardtop%2FCalendarKit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/richardtop/CalendarKit) [![Tag](https://img.shields.io/github/v/tag/richardtop/calendarkit)](https://cocoapods.org/pods/CalendarKit) [![Version](https://img.shields.io/cocoapods/v/CalendarKit)](https://cocoapods.org/pods/CalendarKit) [![YouTube Channel Subscribers](https://img.shields.io/youtube/channel/subscribers/UCx1gvWpy5zjOd7yZyDwmXEA?style=social)](https://www.youtube.com/channel/UCx1gvWpy5zjOd7yZyDwmXEA?sub_confirmation=1) [![Twitter](https://img.shields.io/twitter/follow/richardtop_ios?style=social)](https://twitter.com/richardtop_ios) [![GitHub followers](https://img.shields.io/github/followers/richardtop?style=social)](https://github.com/richardtop) # CalendarKit **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. ## Tutorials - [Create iOS Calendar App in Swift with CalendarKit - Official Tutorial](https://www.youtube.com/watch?v=cJ63-_z1qg8) - [Live Programming with CalendarKit - For Beginners](https://www.youtube.com/watch?v=krIfO3s3ZrM) ## Need Help? If you have a **programming question** about how to use CalendarKit in your application, ask it on StackOverflow with the [CalendarKit](https://stackoverflow.com/questions/tagged/calendarkit) tag. Check out the [Sample App](https://github.com/richardtop/CalendarApp) for reference. [Create a new Issue from template](https://github.com/richardtop/CalendarKit/issues/new/choose) to report a bug or request a new feature. ## Examples [Video](https://www.youtube.com/watch?v=Fi-Qqp9BaAs) [Sample App](https://github.com/richardtop/CalendarApp) ## Installation CalendarKit can be installed with Swift Package Manager. ### Swift Package Manager 1. In Xcode, open your project and navigate to **File** → **Swift Packages** → **Add Package Dependency...** 2. Paste the repository URL (`https://github.com/richardtop/CalendarKit.git`) and click **Next**. 3. For **Rules**, select **Version (Up to Next Major)** and click **Next**. 4. Click **Finish**. [Adding Package Dependencies to Your App](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app) ## Usage 1. Subclass `DayViewController` 2. Implement `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. ```swift // 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. ### Usage To respond to the user input, override mehtods of `DayViewDelegate`, for example: ```swift override func dayViewDidSelectEventView(_ eventView: EventView) { print("Event has been selected: \(eventview.data)") } override func dayViewDidLongPressEventView(_ eventView: EventView) { print("Event has been longPressed: \(eventView.data)") } ``` ## Localization 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. GermanNorwegian ## Styles 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: 1. Create a new `CalendarStyle` object (or copy existing one) 2. Change style by updating the properties. 3. Invoke `updateStyle` method with the new `CalendarStyle`. ```Swift let style = CalendarStyle() style.backgroundColor = UIColor.black dayView.updateStyle(style) ``` Light theme Dark theme ## Requirements - iOS 11.0+, macOS (Catalyst) 10.15+ - Swift 5.7+ ## Contributing The list of features currently in development can be viewed on the [issues](https://github.com/richardtop/CalendarKit/issues) page. Before contributing, please review [guidelines and code style](https://github.com/richardtop/CalendarKit/blob/master/CONTRIBUTING.md). ## Author Richard Topchii ## License **CalendarKit** is available under the MIT license. See the LICENSE file for more info.