CalendarView 1.1.2

CalendarView 1.1.2

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最后发布2016年2月
SPM支持 SPM

Nate ArmstrongNate Armstrong 维护。




CalendarView

使用方法

要运行示例项目,先克隆仓库,然后在 CalendarViewDemo 目录下运行 pod install

需求

  • iOS 8.3+
  • Xcode 6.3

安装

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

pod "CalendarView"

截图

   

使用方法

在代码中使用 CalendarView

let calendar = CalendarView(frame: CGRectMake(0, 0, CGRectGetWidth(view.frame), 320))
view.addSubview(calendar)

或作为输出(支持自动布局)

@IBOutlet weak var calendar: CalendarView!

选择特定日期

默认情况下,选中日期为当前日期。您可以使用 selectDate(date: Moment) 方法选择任何日期。

let date: NSDate = MY_NSDATE
calendar.selectDate(moment(date))

代理

CalendarView 的代理会收到两个事件的通知

calendarDidSelectDate(date: Moment) // called when user taps a date
calendarDidPageToDate(date: Moment) // called when users swipes month

CalendarView 类使用 SwiftMoment 进行日期操作。

代理调用示例

extension ViewController: CalendarViewDelegate {

  func calendarDidSelectDate(date: Moment) {
    title = date.format(dateFormat: "MMMM d, yyyy")
  }

  func calendarDidPageToDate(date: Moment) {
    title = date.format(dateFormat: "MMMM d, yyyy")
  }

}

定制

目标是使日历尽可能可定制,同时又不使其过于复杂和臃肿。

外观

您可以通过设置 CalendarView 的某些类属性来自定义日历的外观。

import UIKit
import CalendarView

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  var window: UIWindow?


  func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // Calendar appearance
    CalendarView.daySelectedBackgroundColor = UIColor.secondaryColor()
    CalendarView.daySelectedTextColor = UIColor.whiteColor()
    CalendarView.todayBackgroundColor = UIColor(white: 0.0, alpha: 0.3)
    CalendarView.todayTextColor = UIColor.whiteColor()
    CalendarView.otherMonthBackgroundColor = UIColor.clearColor()
    CalendarView.otherMonthTextColor = UIColor(white: 1.0, alpha: 0.3)
    CalendarView.dayTextColor = UIColor(white: 1.0, alpha: 0.6)
    CalendarView.dayBackgroundColor = UIColor.clearColor()
    CalendarView.weekLabelTextColor = UIColor(white: 1.0, alpha: 0.3)

    return true
  }
}

滑动选中的日期

默认情况下,用户拖动到不同月份时,系统会自动选择该月的第一天。您可以通过修改 CalendarView 实例的 selectedDayOnPaged 属性来自定义此行为。

public var selectedDayOnPaged: Int? = 1

如果设置为 nil,则拖动时不会自动选择任何一天。

作者

Nate Armstrong,[email protected]

许可证

CalendarView 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。