HKCalendarView 0.0.30

HKCalendarView 0.0.30

Kyryl Horbushko维护。



  • 作者:
  • Kyryl

CalendarView

轻量级的库,用于在您的应用中显示单视图日历。支持由原生 iOS SDK 支持的任何日历。

Swift ICONKit-license Platform type

demo

安装

使用 CocoaPods

只需将以下行添加到您的 Podfile 中

pod 'HKCalendarView'

这将在您下次运行 pod install 执行期间将 CalendarView 二进制文件和依赖项下载到 Pods/

这是安装特定版本 CalendarView 的推荐方法。

使用

  • 将视图添加到您的界面中,并指定类名 CalendarView

demo

或者,您也可以在代码中创建视图并添加到界面中

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)
  • 从 View 中获取 IBOutlet

@IBOutlet private weak var calendarView: CalendarView!

这就完成了!

高级配置

为创建自己的UI版本使用不同的代理

示例 - 自定义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*/
  }
}

有关配置的详细信息,请参阅每个类的示例和文档

结果

demo

您还可以使用不同的选项来更改应用程序的行为。

  /// 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]
附加功能

日历视图还提供自定义日历,例如从公元1356年(1937年3月14日)到1500年(2077年11月16日)的 UmmAlQuaraCalendar。注意:在此间隔之外,转换器将给出错误的结果。描述请见此处 www.staff.science.uu.nl

基于

链接

用法

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

示例

demo demo demo demo

待办事项

  • 测试
  • 多日期选择
  • 日期范围选择
  • 用户自定义动画

需求

  • 支持Xcode 10及以上版本
  • 支持iOS 11及以上版本
  • 支持Swift 5及以上版本
  • CocoaPods

许可协议

MIT协议许可。

联系

关于CalendarView有任何问题或问题?请创建一个问题

如果你希望贡献——只需创建一个拉取请求。