RSDayFlow 1.8.0

RSDayFlow 1.8.0

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新发布2020年1月

Ruslan Skorb 维护。



RSDayFlow 1.8.0

  • Evadne Wu 和 Ruslan Skorb

RSDayFlow Build Status CocoaPods Carthage compatible

Sample

iOS 7 无限滚动日历。只需4行代码即可设置。

RSDayFlow 是基于 DayFlow 的精简分支,包含更新和扩展。

  • 目前选中单元格的视觉反馈
  • 可以标记日期
  • 设计风格与 iOS 7 类似
  • 更多更新

安装

CocoaPods 是推荐安装 RSDayFlow 的方法。只需将以下行添加到 Podfile

Podfile

pod 'RSDayFlow'

基本用法

导入类头。

#import "RSDFDatePickerView.h"

只需创建你的日期选择器视图,并在必要时设置代理/数据源。

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    RSDFDatePickerView *datePickerView = [[RSDFDatePickerView alloc] initWithFrame:self.view.bounds];
    datePickerView.delegate = self;
    datePickerView.dataSource = self;
    [self.view addSubview:datePickerView];
}

代理(可选)

RSDFDatePickerView提供三个代理方法。方法datePickerView:shouldHighlightDate:询问代理在追踪期间日期是否应该突出显示。方法datePickerView:shouldSelectDate:询问代理指定的日期是否应该被选中。方法datePickerView:didSelectDate:在用户点击特定日期时调用。要使用它们,在你的视图控制器中实现代理。

@interface ViewController () <RSDFDatePickerViewDelegate>

然后实现代理函数。

// Returns YES if the date should be highlighted or NO if it should not.
- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldHighlightDate:(NSDate *)date
{
    return YES;
}

// Returns YES if the date should be selected or NO if it should not.
- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldSelectDate:(NSDate *)date
{
    return YES;
}

// Prints out the selected date.
- (void)datePickerView:(RSDFDatePickerView *)view didSelectDate:(NSDate *)date
{
    NSLog(@"%@", [date description]);
}

数据源(可选)

RSDFDatePickerView提供三个数据源方法。方法datePickerView:shouldMarkDate:询问数据源是否应该标记日期。方法datePickerView:markImageColorForDate:询问数据源关于指定日期的默认标记图像的颜色。方法datePickerView:markImageForDate:询问数据源关于指定日期的标记图像。如果实现了方法datePickerView:markImageForDate:,则将忽略方法datePickerView:markImageColorForDate:。要使用这些方法,在你的视图控制器中实现数据源。

@interface ViewController () <RSDFDatePickerViewDataSource>

然后实现数据源函数。

// Returns YES if the date should be marked or NO if it should not.
- (BOOL)datePickerView:(RSDFDatePickerView *)view shouldMarkDate:(NSDate *)date
{
    // The date is an `NSDate` object without time components.
    // So, we need to use dates without time components.
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    unsigned unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit;
    NSDateComponents *todayComponents = [calendar components:unitFlags fromDate:[NSDate date]];
    NSDate *today = [calendar dateFromComponents:todayComponents];
    
    return [date isEqual:today];
}

// Returns the color of the default mark image for the specified date.
- (UIColor *)datePickerView:(RSDFDatePickerView *)view markImageColorForDate:(NSDate *)date
{
    if (arc4random() % 2 == 0) {
        return [UIColor grayColor];
    } else {
        return [UIColor greenColor];
    }
}

// Returns the mark image for the specified date.
- (UIImage *)datePickerView:(RSDFDatePickerView *)view markImageForDate:(NSDate *)date
{
    if (arc4random() % 2 == 0) {
        return [UIImage imageNamed:@"img_gray_mark"];
    } else {
        return [UIImage imageNamed:@"img_green_mark"];
    }
}

自定义

每个视图都可以自定义以满足您的需求。创建所需视图的子类并覆盖默认值。

即将推出

  • 如果您希望请求一项新功能,请随时提交问题。

演示

在Xcode中构建并运行RSDayFlowExample项目,以查看RSDayFlow的实际应用。享受过程。让它更快。Fork并提交pull请求。找出可定制的钩子。

联系

Ruslan Skorb

许可

此项目可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。建议通过链接到项目页面进行归属。