SwiftWeeklyCalendar
这个日历作用类似原生 iOS 周日历,可以水平垂直滚动,横向如果拉动手势长则滚动至下个或上个周,如果短则滚动至下个或上一天
重要
它在 iOS 10 或更高版本的 Swift 5 上运行
示例
要运行示例项目,首先克隆仓库,然后在 Example 目录中运行 pod install
。
安装
SwiftWeeklyCalendar 可通过 CocoaPods 提供。要安装它,请简单地将以下行添加到您的 Podfile 中。
pod 'SwiftWeeklyCalendar'
作者
mmachado53, [邮箱地址已加密]
使用
基本概念
Class WeeklyCalendarCollectionView
WeeklyCalendarCollectionView 是日历的基础,并扩展了UICollectionView
WeeklyCalendarCollectionView出口(从Interface Builder可访问的属性)
- calendarDelegate:WeeklyCalendarCollectionViewDelegate?
- headerCollectionView:CalendarHeaderCollectionView?
- hoursCollectionView:CalendarHoursCollectionView?
- customHeightPerHour:CGFloat = -1 (如果未设置不同的值,则不能垂直滚动)
- paddingTop:CGFloat = 0
WeeklyCalendarCollectionView 公共属性
- dayCellSize:CGSize 是单元格的当前大小,宽度 = frame.width / 7,高度 = customHeightPerHour * 24
WeeklyCalendarCollectionView 公共方法
-设定日期(date:Date) : 导航到指定日期
Class CalendarHeaderCollectionView
CalendarHeaderCollectionView 是您可以展示周日期的视图,并扩展了 UICollectionView
CalendarHeaderCollectionView 输出口(从界面构建器可访问的属性)
- calendarHeaderDelegate:CalendarHeaderCollectionViewDelegate?
Class CalendarHoursCollectionView
CalendarHoursCollectionView 是您可以展示小时和扩展的视图,并扩展了 UICollectionView
CalendarHoursCollectionView 输出口(从界面构建器可访问的属性)
- CalendarHoursDelegate:CalendarHoursCollectionViewDelegate?
协议. 代理的用法
CustomViewController.swift
import SwiftWeeklyCalendar
extension CustomViewController : WeeklyCalendarCollectionViewDelegate{
func weeklyCalendarCollectionView(_ collectionView: WeeklyCalendarCollectionView, cellFor date: Date, indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellidentifier", for: indexPath)
// Configure here the cell view for date in WeeklyCalendarCollectionView instance
return cell
}
func weeklyCalendarCollectionView(collectionView: WeeklyCalendarCollectionView, changeWeek dates: [Date]) {
// "dates" its an array with visible dates
// do something when the calendar has changed date
}
func weeklyCalendarCollectionView(collectionView: WeeklyCalendarCollectionView, didSelectItemAt cellState: Date) {
}
}
extension CustomViewController : CalendarHeaderCollectionViewDelegate {
func calendarHeaderCollectionView(_ collectionView: CalendarHeaderCollectionView, cellFor date: Date, indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellidentifier", for: indexPath)
// Configure here the cell view for headers in the CalendarHeaderCollectionView instance
return cell
}
}
extension CustomViewController : CalendarHoursCollectionViewDelegate {
func calendarHoursCollectionView(_ collectionView: CalendarHoursCollectionView, cellFor hour: Int, indexPath: IndexPath) -> UICollectionViewCell {
let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellidentifier", for: indexPath)
// Configure here the cell view for headers in the CalendarHoursCollectionView instance
return cell
}
}
视频教程
即将推出 :)
许可
SwiftWeeklyCalendar遵循MIT许可。有关更多信息,请参阅LICENSE文件。