日历热力图
简介
CalendarHeatmap
是一个基于日历的热力图,以颜色呈现数据点的时序,受 GitHub 贡献图表的启发,使用 Swift 编写。
安装
CalendarHeatmap 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'CalendarHeatmap'
您也可以通过 Carthage 安装 CalendarHeatmap,通过将其添加到您的 Cartfile 中
github "Zacharysp/CalendarHeatmap"
用法
// minimum usage.
let startDate = Date()
let calendarHeatmap = CalendarHeatmap(startDate: startDate)
calendarHeatmap.delegate = self
view.addSubview(calendarHeatmap)
// provide a range of date.
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
let startDate = formatter.date(from: "2019-10-18")
let endDate = formatter.date(from: "2020-02-14")
// default endDate is now.
let calendarHeatmap = CalendarHeatmap(startDate: startDate, endDate: endDate)
// you could custom the heatmap by using CalendarHeatmapConfig.
let config = CalendarHeatmapConfig()
let calendarHeatmap = CalendarHeatmap(config: config, startDate: Date())
// reload the heatmap
let calendarHeatmap = CalendarHeatmap(startDate: ...)
calendarHeatmap.reload()
// reload with new range of date.
calendarHeatmap.reload(newStartDate: ..., newEndDate: ...)
CalendarHeatmapConfig
详细信息。
配置键 | 类型 | 默认值 |
---|---|---|
backgroundColor | UIColor | UIColor.white |
contentRightInset | CGFloat | 60 |
itemColor | UIColor | UIColor.clear |
itemSide | CGFloat | 20 |
interitemSpacing | CGFloat | 4 |
lineSpacing | CGFloat | 4 |
weekDayColor | UIColor | UIColor.black |
weekDayStrings | [String] | DateFormatter().shortWeekdaySymbols.map{ \$0.capitalized } |
weekDayFont | UIFont | UIFont.systemFont(ofSize: 12, weight: .medium) |
weekDayWidth | CGFloat | 30 |
weekDayStandard | 枚举 | USandCanada |
monthColor | UIColor | UIColor.black |
monthStrings | [String] | DateFormatter().monthSymbols |
monthFont | UIFont | UIFont.systemFont(ofSize: 12, weight: .medium) |
monthHeight | CGFloat | 20 |
从 Monday 或 Sunday 开始。
var config = CalendarHeatmapConfig()
config.weekDayStandard = .USandCanada // starts Sunday. (default)
config.weekDayStandard = .International // starts Monday
以编程方式滚动日历
calendarHeatMap.scrollTo(date: Date(...), at: .right, animated: false)
让您的 ViewController
遵循 CalendarHeatmapDelegate
// color for date
func colorFor(dateComponents: DateComponents) -> UIColor {
guard let year = dateComponents.year,
let month = dateComponents.month,
let day = dateComponents.day else { return .clear}
// manage your color based on date here
let yourColor = {...}
return yourColor
}
// (optional) selection at date
func didSelectedAt(dateComponents: DateComponents) {
guard let year = dateComponents.year,
let month = dateComponents.month,
let day = dateComponents.day else { return }
// do something here
}
// (optional) notify finish loading the calendar
func finishLoadCalendar() {
// do something here
}
演示
查看 示例
,要运行示例项目,请先克隆存储库,然后从示例目录运行 pod install
。
作者
Zacharysp, [email protected]
许可证
CalendarHeatmap 依据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。