khorbushko / CalendarView

Calendar control that represent any calendar type supported by native iOS SDK, provide high performance and high customizablility

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CalendarView

Lightweight lib for displaying singleView calendar in your app. Support any calendar supported by native iOS SDK.

Swift ICONKit-license Platform type

demo

Installation

Using CocoaPods:

Simply add the following line to your Podfile:

pod 'HKCalendarView'

This will download the CalendarView binaries and dependencies in Pods/ during your next pod install execution.

This is the recommended way to install a specific version of CalendarView.

Usage

  • add view to your interface and specify class name CalendarView

demo

Or alternatively just create view in code and add it to your interface

let calendarView = CalendarView(frame: CGRect(x: 0, y:0. width: 350, height: 350)
let insets = UIEdgeInsets.zero // or any you like
calendarView.translatesAutoresizingMaskIntoConstraints = false

let views = [
	"subview": calendarView
]
let metrics = [
	"left": insets.left,
	"right": insets.right,
	"top": insets.top,
	"bottom": insets.bottom
]

superview.addSubview(calendarView)
var constraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|-left-[subview]-right-|",
                                                       options: [.alignAllLeading, .alignAllTrailing],
                                                       metrics: metrics,
                                                       views: views)
constraints.append(contentsOf: NSLayoutConstraint.constraints(withVisualFormat: "V:|-top-[subview]-bottom-|",
	                                                    options: [.alignAllTop, .alignAllBottom],
	                                                    metrics: metrics,
	                                                    views: views))
NSLayoutConstraint.activate(constraints)
  • grab IBOutlet from View

@IBOutlet private weak var calendarView: CalendarView!

That's it - you done!

Advanced configuration

User different delegates for preparing own version of UI

Example - own UI

extension ViewController: CalendarViewItemProviderDelegate {

  func calendarView(didRequestBuildComponentsForRegistration calendarView: CalendarView) -> [CalendarItemPresentable.Type] {
    /*you can provide array of items*/
    return [MyDateItem.self]
  }

  func calendarView(_ calendarView: CalendarView, didRequestDateItemFor date: Date, timeline: Timeline) -> CalendarDateItemPresentable {
    /*create any item from provided array types in func above*/
    let item = MyDateItem(date: date, timeline: timeline)
    return item
  }

  func calendarView(_ calendarView: CalendarView,
                    didRequestWeekDayItemFor style: CalendarWeekSymbolType,
                    forWeekNameItem item: CalendarWeekDayViewPosition,
                    poposedName name: String,
                    timeline: Timeline) -> CalendarWeekDayItemPresentable {
    /*create any item from provided array types in func above*/
    /*check poposedName and style and modify if u want*/
    let item = MyDateItem(weekDayName: name, timeline: timeline)
    return item
  }

  func calendarView(_ calendarView: CalendarView, didCompleteConfigure cell: CalendarItemConfigurable, for buildItem: CalendarItemPresentable) {
    /*modify cell additionally as u wish here*/
  }
}

For details of configuration - please see example and documentation for each class

Result:

demo

Also u can use different options for changing behaviour of app.

  /// This option allow some debug prints, usefull for checking behaviour of different calendar
  /// as result u will see date in selected calendar and in gregorian calendar in same line
  public static let debugMode = CalendarAppearenceOption(rawValue: 1 << 0)

  /// Enable enclosing (prev and next) month to be displayed
  public static let showEnclosingMonth = CalendarAppearenceOption(rawValue: 1 << 1)

  /// If enabled **showEnclosingMonth** option, this option will allow date selection for non selected month
  public static let enableEnclosingMonthSelection = CalendarAppearenceOption(rawValue: 1 << 2)

  /// If enabled **showEnclosingMonth** option, day's that are in current month will be hightlighted
  public static let hightlightCurrentMonth = CalendarAppearenceOption(rawValue: 1 << 3)

  /// If selected `CalendarSelectionType.single`, this option may enable deselect already selected item
  public static let allowSingleDeselectionForSingleMode = CalendarAppearenceOption(rawValue: 1 << 4)

  /// If enabled **showEnclosingMonth** option, day's that are in current month always will display 7 rows
  public static let showConstantCount = CalendarAppearenceOption(rawValue: 1 << 5)

  /// Represent set of minimal (non) option for calendar
  public static let noOption: CalendarAppearenceOption = []

  /// Default set of options for calendar - `showEnclosingMonth` and `hightlightCurrentMonth`
  public static let `default`: CalendarAppearenceOption = [.showEnclosingMonth, .hightlightCurrentMonth]
additional

Calendar view also provide custom calendar such as UmmAlQuaraCalendar in range from 1356 AH (14 March 1937 CE) to 1500 AH (16 November 2077 CE) Note: Outside this interval, the converter will give erroneous results Description available here www.staff.science.uu.nl

based on:

Links:

usage:

// somewhere in your code
   calendarView.switchToCustomCalendarType(.ummAlQura, locale: Locale(identifier: "ar"))

Samples:

demo demo demo demo

TODO

  • test
  • multiselection of dates
  • range date selection
  • user-defined animation

Requirement

  • Xcode 10 or higher
  • iOS 11 or higher
  • Swift 5 or higher
  • Cocoapods

License

MIT licensed.

Contact

Have a question or an issue about CalendarView? Create an issue!

If you would like to contribute - just create a pull request.

About

Calendar control that represent any calendar type supported by native iOS SDK, provide high performance and high customizablility

License:MIT License


Languages

Language:Swift 97.5%Language:Ruby 2.5%