// // LDCalendarView.m // YouHuiProject // // Created by 小花 on 2018/8/3. // Copyright © 2018年 kuxuan. All rights reserved. // #import "LDCalendarView.h" #import "LXCalender.h" @interface LDCalendarView(){ __block NSString *_dateStr; } @property(nonatomic,strong) LXCalendarView *calenderView; @end @implementation LDCalendarView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = Fitsize(6); self.layer.masksToBounds = YES; [self initSubViews]; } return self; } - (void)initSubViews { self.calenderView =[[LXCalendarView alloc]initWithFrame:CGRectMake(0, 0, self.width, 0)]; self.calenderView.layer.masksToBounds = YES; self.calenderView.currentMonthTitleColor =[UIColor YHColorWithHex:0x2c2c2c]; self.calenderView.lastMonthTitleColor =[UIColor YHColorWithHex:0x8a8a8a]; self.calenderView.nextMonthTitleColor =[UIColor YHColorWithHex:0x8a8a8a]; self.calenderView.isHaveAnimation = YES; self.calenderView.isCanScroll = YES; self.calenderView.isShowLastAndNextBtn = YES; self.calenderView.todayTitleColor =[UIColor homeRedColor]; self.calenderView.selectBackColor =[UIColor homeRedColor]; self.calenderView.isShowLastAndNextDate = NO; [self.calenderView dealData]; self.calenderView.backgroundColor =[UIColor whiteColor]; self.calenderView.selectBlock = ^(NSInteger year, NSInteger month, NSInteger day) { NSLog(@"%ld年 - %ld月 - %ld日",year,month,day); _dateStr = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day]; }; [self addSubview:self.calenderView]; UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.calenderView.bottom, self.width, Fitsize(60))]; bottomView.backgroundColor = [UIColor whiteColor]; UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 0, Fitsize(60), bottomView.height)]; [leftBtn setTitle:@"取消" forState:UIControlStateNormal]; [leftBtn setImage:[UIImage imageNamed:@"cancel_c"] forState:UIControlStateNormal]; [leftBtn setTitleColor:[UIColor YHColorWithHex:0x2C3135] forState:UIControlStateNormal]; leftBtn.titleLabel.font = [UIFont systemFontOfSize:Fitsize(12)]; [leftBtn addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside]; [leftBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:5]; [bottomView addSubview:leftBtn]; UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(bottomView.width-15-Fitsize(60), 0, Fitsize(60), bottomView.height)]; [rightButton setTitleColor:[UIColor YHColorWithHex:0x2C3135] forState:UIControlStateNormal]; rightButton.titleLabel.font = [UIFont systemFontOfSize:Fitsize(12)]; [rightButton setTitle:@"确定" forState:UIControlStateNormal]; [rightButton setImage:[UIImage imageNamed:@"save_c"] forState:UIControlStateNormal]; [rightButton setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:5]; [rightButton addTarget:self action:@selector(makeSureAction) forControlEvents:UIControlEventTouchUpInside]; [bottomView addSubview:rightButton]; [self addSubview:bottomView]; self.height = self.calenderView.height+bottomView.height; } - (void)cancelAction { if (self.cancelBlock) { self.cancelBlock(); } } - (void)makeSureAction { if (self.makeSureBlock) { if (!_dateStr) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSDate *datenow = [NSDate date]; _dateStr = [formatter stringFromDate:datenow]; } self.makeSureBlock(_dateStr); } } @end