Skip to content

πŸ“… Calendar for iOS and iPadOS in Swift

License

Notifications You must be signed in to change notification settings

sachithras/CalendarKit

Β 
Β 

Repository files navigation

CalendarKit License Platform Version SwiftPM compatible

CalendarKit

CalendarKit is a fully customizable calendar library written in Swift. It was designed to look similar to the iOS Calendar app, but allow customization if needed. To make modifications easier, CalendarKit is composed of multiple small modules. They can be used together, or on their own.

Need Help?

If you have a programming question about how to use CalendarKit in your application, ask it on StackOverflow using the CalendarKit tag.

Please, use GitHub Issues only for reporting a bug or requesting a new feature in the library.

Demo

You can try CalendarKit with CocoaPods. Just enter in Terminal:

pod try CalendarKit

Watch demo video

Try it live in your browser

Installation

Swift Package Manager (Xcode 11 or higher)

The preferred way of installing CalendarKit is via the Swift Package Manager.

Xcode 11 integrates with libSwiftPM to provide support for iOS, watchOS, and tvOS platforms.

  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 Branch (with branch set to master).
  4. Click Finish.

A more detailed guide can be found here: Adding Package Dependencies to Your App

CocoaPods

To install it, add the following line to your Podfile:

pod 'CalendarKit'

Usage

Subclass DayViewController and implement DayViewDataSource protocol to show events. CalendarKit requires DayViewDataSource to return an array of objects conforming to EventDescriptor protocol, specifying all the information needed to display a particular event:

// Return an array of EventDescriptors for particular date
override func eventsForDate(_ date: Date) -> [EventDescriptor] {
  var models = // Get events (models) from the storage / API

  var events = [Event]()

  for model in models {
      // Create new EventView
      let event = Event()
      // Specify StartDate and EndDate
      event.startDate = model.startDate
      event.endDate = 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
}

There is no need to do layout, CalendarKit will take care of it. CalendarKit also creates EventViews for you and reuses them.

If needed, implement DayViewDelegate to handle user input

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 iOS locale. Here are few examples:

GermanNorwegianFinnish

Styles

CalendarKit's look can be easily customized. The steps needed for customizations 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.
let style = CalendarStyle()
style.backgroundColor = UIColor.black
dayView.updateStyle(style)

Light theme Dark theme

Requirements

  • iOS 9.0+
  • Swift 4+ (Library is written in Swift 5)

Dependencies

Contributing

The list of features currently in development can be viewed on the issues page.

Before contributing, please review guidelines and code style.

Author

Richard Topchii

License

CalendarKit is available under the MIT license. See the LICENSE file for more info.

About

πŸ“… Calendar for iOS and iPadOS in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.4%
  • Ruby 0.6%