TTCalendarPicker 0.1.7

TTCalendarPicker 0.1.7

Óscar Morales VivóKevin BeaulieuDaniel Roth 维护。



  • 作者:
  • Daniel Roth

TTCalendarPicker

Version License Platform

TTCalendarPicker 是一个轻量级、高度可配置、无限滚动的日历选择视图。TTCalendarPicker 由 Thumbtack, Inc 的 iOS 团队开发,并目前正在驱动我们的样式日历选择器。虽然我们不太可能添加我们不打算在我们自己的应用中使用的功能请求,但我们会对发现的错误进行积极修复。

示例

要运行示例项目,克隆仓库,然后首先从 Example 目录运行 pod install。然后构建并运行 TTCalendarPicker-Example 项目。

要求

  • iOS 10.0+
  • Xcode 10.0+
  • Swift 4.0+

安装

TTCalendarPicker 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'TTCalendarPicker'

使用方法

基本日历

使用 TTCalendarPicker 最低要求包括

  1. 创建一个 TTCalendarPicker.CalendarPicker 对象。默认情况下,CalendarPicker 将使用用户当前的、基于区域设置的日历。
  2. 对日历进行限制,以确保它具有一个明确的宽度。日历将根据其宽度、其 calendarHeightMode 和其 cellHeightMode 来约束它自己的高度。
  3. 向 calendarPicker 提供一个 dataSource 对象,并注册一个 dateCell 类/nib,例如
    calendarPicker.registerDateCell(DateCell.self, withReuseIdentifier: "DateCell")
  4. 在 calendarPicker 的数据源中, dequeue 并配置给定日期的单元格,例如
    func calendarPicker(_ calendarPicker: CalendarPicker, cellForDay day: Int,
                        month: Int, year: Int, inVisibleMonth: Bool, at indexPath: IndexPath) -> UICollectionViewCell {
        let cell = calendarPicker.dequeReusableDateCell(
            withReuseIdentifier: "DateCell",
            indexPath: indexPath)
            as! DateCell
        cell.setText("\(day)")
        cell.isInVisibleMonth = inVisibleMonth
        return cell
    }

配置日历

TTCalendarPicker 具有高度可定制性。由于日期单元格和月份标题由开发者提供,因此它可以支持几乎所有您能想到的设计。此外,TTCalendarPicker 支持以下配置属性

previousMonthCount

类型: Int
默认: nil
用户应能向前滚动到初始月份之前多少个月的月份。

additionalMonthCount

类型: Int
默认: nil
用户应能向后滚动到初始月份之后多少个月的月份。

calendarHeightMode

类型: TTCalendarPicker.CalendarHeightMode
默认: .fixed

  • .fixed:始终显示一个月中可能出现的最大周数。
  • .dynamic:根据显示的可见月份中的周数调整大小。

cellHeightMode

类型: TTCalendarPicker.CellHeightMode
默认: .aspectRatio(0.88)
可以是 .fixed(行具有固定高度)或 .aspectRatio(单元格高度取决于其宽度)。

gridInsets

类型: UIEdgeInsets
默认: UIEdgeInsets(top: 12.0, left: 16.0, bottom: 12.0, right: 16.0)
日期单元格网格的内边距

cellSpacingX

类型: CGFloat
默认: 1.0
日期列之间的空间

cellSpacingY

类型: CGFloat
默认: 1.0
日期行之间的空间

monthHeaderHeight

类型: CGFloat?
默认: nil 分配给可选的monthHeaderView 的高度

selectedDates

类型: [Date]
默认: []
当前在calendarPicker的日历中选中时间的午夜时刻

allowsmultipleselection

类型: Bool
默认: false
是否选中其他日期时应该取消之前选择的日期

gridColor

类型: UIColor
默认: .clear
cellSpacingXcellSpacingY 定义的区域的颜色

贡献指南

所有贡献都受欢迎,前提是此代码正在被生产应用积极使用,并且我们不太可能提交我们不打算使用或者可能不利于代码库稳定性的更改。

作者

由 Daniel Roth 初始化 - [email protected],
并得到Thumbtack此处整个iOS团队的持续贡献。

许可证

TTCalendarPicker 适用于 Apache 2.0 许可证。更多信息请参阅 LICENSE 文件。