Giter VIP home page Giter VIP logo

calendarkit's Introduction

CalendarKit CI Status Version License Platform

CalendarKit

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

Demo

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

pod try CalendarKit

Watch demo video

Try it live in your browser

Installation

CalendarKit is available through CocoaPods. To install it, simply 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 TimePeriod
      let datePeriod = TimePeriod(beginning: model.beginning, end: model.start)
      event.datePeriod = datePeriod
      // 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(view)
  }

  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:

Finnish


German


Norwegian

Styles

CalendarKit's look can easily be customized. Just new CalendarStyle object to DayView's updateStyle method:

let style = CalendarStyle()
style.backgroundColor = UIColor.black
dayView.updateStyle(style)

Light theme Dark theme

Requirements

  • iOS 9.0+
  • Swift 3.0+

Dependencies

  • Neon is used for declarative layout
  • DateTools is used for date manipulation

Roadmap

CalendarKit is under development, API can and will be changed.

  • Improve customization
  • Landscape support
  • Add to Carthage
  • Documentation

Author

Richard Topchii

License

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

calendarkit's People

Contributors

richardtop avatar v-ken avatar danlozano avatar zenangst avatar basthomas avatar diego-ta avatar keith-nativemobile avatar rich86man avatar vadymmarkov avatar

Watchers

James Cloos avatar Mukul More avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.