美文网首页
iOS 自定义日历日期选择

iOS 自定义日历日期选择

作者: 无敌小蚂蚱这个名字被占用了 | 来源:发表于2019-04-03 15:43 被阅读0次

    MLMCalendarView 一句代码搞定日历日期选择

    star支持 请移驾GitHub地址

    日期可单选, 可多选 ,可自定义主题颜色,带农历日期显示(可选)

    先看下效果图

    效果图.jpg

    安装教程

    1. CocoaPods安装:
        Podfile文件 输入 
         
        pod 'MLMCalendarView','1.0.1'
    

    //如不是最新版本,请更新本地pod索引库

    2. 手动安装
        下载该项目
        把文件夹中的“MLCalendar”文件夹add到自己项目中即可
    

    使用说明

    1. 引入头文件 #import "MLCalendar.h"
    #import "MLCalendar.h"
     
    //方式1(推荐)
    /*
    MaxTotal 最多可选的天数  单选 = 1
    mainColor 主题颜色
    calendarBlock 确定回调
    
    */
    
    [[MLCalendarManager shareManager] showCalendarViewMaxTotal:4 mainColor:[UIColor redColor] calendarBlock:^(NSString * _Nonnull beginDate, NSString * _Nonnull endDate, NSInteger total) {
    
             //(单选时起始日期和结束日期一致,总天数为1)
             NSLog(@"%@ --- %@ === %ld",beginDate,endDate,total);
    
    }];
    
    //方式2
    /*
    创建 MLCalendarView
    */
    @property (nonatomic,strong)MLCalendarView * calendarView;
    
    
    self.calendarView = [[MLCalendarView alloc] initWithFrame:CGRectMake(0, 100, MLMainScreenOfWidth,            MLMainScreenOfHeight - 100)];
        
        self.calendarView.backgroundColor = [UIColor whiteColor];
        
        self.calendarView.multiSelect = YES;//是否多选
        
        self.calendarView.maxTotal = maxTotal;//可选择总天数
        
        self.calendarView.mlColor = [UIColor redColor];//主题颜色
        
        self.calendarView.hiddenLunar = No;//是否显示农历日期
        
        [self.calendarView constructionUI];//构建
        
        [[UIApplication sharedApplication].keyWindow addSubview:self.calendarView];//添加到superView
        
        __weak typeof(self) weakSelf = self;
    
        //取消回调
        self.calendarView.cancelBlock = ^{
            
            [weakSelf removeCalendarView];
        };
        //单选回调
        self.calendarView.selectBlock = ^(NSString *date) {
            
            NSLog(@"%@",datel);
            
            [weakSelf removeCalendarView];
        };
        //多选回调
        self.calendarView.multiSelectBlock = ^(NSString *beginDate, NSString *endDate, NSInteger total) {
            
            NSLog(@"%@ --- %@ === %ld",beginDate,endDate,total);
            [weakSelf removeCalendarView];
        };
    
                  感谢您的来访 
                  如有好的建议或者需求可随时联系我 我会及时认真对待 
                  Thank you very much
    

    star支持 请移驾GitHub地址

    相关文章

      网友评论

          本文标题:iOS 自定义日历日期选择

          本文链接:https://www.haomeiwen.com/subject/lojzbqtx.html