项目作者: akaashdev

项目描述 :
Events Calendar is a user-friendly iOS Swift library that helps you achieve a cool Calendar UI with events mapping.
高级语言: Swift
项目地址: git://github.com/akaashdev/EventsCalendar.git
创建时间: 2019-05-14T11:23:45Z
项目社区:https://github.com/akaashdev/EventsCalendar

开源协议:MIT License

下载


EventsCalendar

CI Status
Version
License
Platform

Events Calendar is a light-weight iOS Swift library that helps you easily create customizable Calendar UI with events mapping. It supports both sync and async events loading. It is very light and optimized that it allows to achieve ~60 fps rendering easily. Achieves smooth scrolling and takes less memory. The attributes of calendar UI are completely customizable.

Screenshots





Usage

Initialization

CalendarView is available in both Week format and Month format. Usage of both the format is similar.
Initialize a MonthCalendarView by:

  1. lazy var monthCalendarView = {
  2. let view = MonthCalendarView(
  3. startDate: Date(fromFormattedString: "2000 01 01")!,
  4. endDate: Date(fromFormattedString: "2050 12 01")!
  5. )
  6. view.allowsDateSelection = true // default value: true
  7. view.selectedDate = Date()
  8. view.isPagingEnabled = true // default value: true
  9. view.scrollDirection = .horizontal // default value: .horizontal
  10. view.viewConfiguration = CalendarConfig() // default valut: .default
  11. return view
  12. }()

WeekCalendarView can be initialized the same way.

Calendar UI configuration

The UI of the calendar is determined by CalendarConfig object, which is passed to viewConfiguration property of CalendarView.
CalendarConfig consists of more than 25 customizable properties. The properties are:

  1. backgroundColor: UIColor // background color of calendar
  2. selectionColor: UIColor // selected date background color
  3. dotColor: UIColor // event dot color
  4. selectedDotColor: UIColor // event dot color of selected date
  5. weekendLabelColor: UIColor // weekend date text color
  6. validLabelColor: UIColor // valid date text color
  7. invalidLabelColor: UIColor // invalid date text color
  8. selectedLabelColor: UIColor // selected date text color
  9. todayLabelColor: UIColor // today date text color
  10. otherMonthLabelColor: UIColor // other month date text color
  11. dateLabelFont: UIFont // font of date text
  12. cellMaxWidth: CGFloat? // maximum width of each date cell
  13. cellMaxHeight: CGFloat? // maximum height of each date cell
  14. invalidatePastDates: Bool // shows past dates invalid date and unselectable
  15. shouldConsiderSaturdayAsWeekend: Bool // considers saturday as weekend
  16. monthTitleFont: UIFont // month title text font
  17. monthTitleHeight: CGFloat // month title text height
  18. monthTitleTextColor: UIColor // month title text color
  19. monthTitleAlignment: NSTextAlignment // month title text alignment
  20. monthTitleBackgroundColor: UIColor // month title background color
  21. monthTitleStyle: MonthTitleStyle // month title style (short, full, ...)
  22. monthTitleIncludesYear: Bool // displays year along with month title
  23. weekdayTitles: [String] // week day titles
  24. weekdayTitleFont: UIFont // week day title text font
  25. weekdayTitleColor: UIColor // week day title text color
  26. weekdayTitleHeight: CGFloat // week day title height
  27. weekdayTitlesBackgroundColor: UIColor // week day title background color

CalendarViewDelegate

Callbacks from CalendarView are called to delegate. Conform your object to CalendarViewDelegate and assign to delegate property of CalendarView

  1. monthCalendarView.delegate = self // self should conform to CalendarViewDelegate

Each time a date selection is changed, the below method of CalendarViewDelegate is called.

  1. func calendarView(_ calendarView: CalendarProtocol, didChangeSelectionDateTo date: Date, at indexPath: IndexPath)

Events Handling

EventsCalendar handles events population both syncronously and asyncronously. CalendarViewDelegate has two optional methods for event handling:

  1. func calendarView(_ calendarView: CalendarProtocol, eventDaysForCalendar type: CalendarViewType, with calendarInfo: CalendarInfo, and referenceDate: Date) -> Set<Int>?
  2. func calendarView(_ calendarView: CalendarProtocol, eventDaysForCalendar type: CalendarViewType, with calendarInfo: CalendarInfo, and referenceDate: Date, completion: @escaping (Result<Set<Int>, Error>)->())

Use the first method if the event days for the current month is readily available.

Use the second method if the event days for the current month must be retreived through a network call or any heavy calculation is required before deciding events for the month. It is advised to do the heavy calculations without blocking the main thread.

Events Caching

Events caching comes by default in EventsCalendar while using events population asyncronously. This helps to reduce redudant network calls or redundant operation for a specific month and improves fast event population in the calendar.
Anyways to turn off event caching, you can use,

  1. monthCalendarView.allowsEventsCaching = false // Default value: true

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 9.0+

Installation

EventsCalendar is available through CocoaPods. To install
it, simply add the following line to your Podfile:

  1. pod 'EventsCalendar'

Author

Akaash Dev, heatblast.akaash@gmail.com

License

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