简单的日历选择器 LDCalendarView

来源:互联网 发布:windows phone 百度云 编辑:程序博客网 时间:2024/06/05 23:42

日历选择器 LDCalendarView简介:

1.今天用红框特殊标注,只能选择今天以后的工作日期,支持跨月份多选;
2.因为每个月的第一天在第一行,所以有时候需要6行才能显示,仿照铁路12306的日历,显示了6行, 选择点击下一个月的日期时会自动切到下一个月,但是可以直接在当前月取消。
测试环境:Xcode 6.2,iOS 6.0 以上





使用示例代码:

#import "ViewController.h"

//导入头文件

#import "LDCalendarView.h"

#import "NSDate+Extend.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *dayLbl;//用于显示选择日期的label

@property(nonatomic,strong)LDCalendarView* calendarView;

@property(nonatomic,strong)NSMutableArray* selectedDate;//用户选择的日期

@end

@implementation ViewController

//显示日历

- (IBAction)showCalendar:(id)sender {

     [self.calendarView show];

}

//懒加载

- (LDCalendarView *)calendarView{

    if (_calendarView == nil) {

        _calendarView = [[LDCalendarView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

        [self.view addSubview:_calendarView];

        

        __weak typeof(self)weakSelf = self;

        _calendarView.complete = ^(NSArray *result) {

            if (result) {

                weakSelf.selectedDate = result.mutableCopy;

                

                //NSMutableArray的排序:从小到大

                [weakSelf.selectedDate sortUsingComparator:^NSComparisonResult(NSNumber *obj1, NSNumber *obj2) {

                    return [obj1 compare:obj2];

                }];

                //格式转换

                NSMutableString *str = [NSMutableString string];

                for (NSNumber *interval in weakSelf.selectedDate) {

                    NSString *partStr = [NSDate stringWithTimestamp:interval.doubleValue format:@"MM.dd"];

                    [str appendFormat:@"%@ ",partStr];

                }

                

                weakSelf.dayLbl.text = str;

            }

        };

    }

    return _calendarView;

}


原创粉丝点击