diff --git a/ALCalendarPicker.podspec b/ALCalendarPicker.podspec index cacee88..a831843 100644 --- a/ALCalendarPicker.podspec +++ b/ALCalendarPicker.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "ALCalendarPicker" - s.version = "1.2.2" + s.version = "1.3.0" s.summary = "简洁简单的日历选择器" # This description is used to generate tags and improve search results. @@ -25,10 +25,11 @@ Pod::Spec.new do |s| # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC -1. 可配置当前日期背景颜色,文字,背景圆角度数 -2. 可配置特殊高亮日期(如预约日期),并且可以配置高亮日期背景颜色,文字,背景圆角度数 -3. 点击日期代理回调 -4. 支持设定起始日期 + 1. 可配置当前日期背景颜色,文字,背景圆角度数 + 2. 可配置特殊高亮日期(如预约日期),并且可以配置高亮日期背景颜色,文字,背景圆角度数 + 3. 点击日期代理回调 + 4. 支持设定起始日期 + 5. 支持点击给日期添加选择样式 DESC s.homepage = "https://github.com/Arc-lin/ALCalendarPicker" diff --git a/ALCalendarPicker/ALCalendarCollectionView.m b/ALCalendarPicker/ALCalendarCollectionView.m index 55b2a3f..f3ff6ec 100644 --- a/ALCalendarPicker/ALCalendarCollectionView.m +++ b/ALCalendarPicker/ALCalendarCollectionView.m @@ -78,6 +78,11 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell cell.layer.cornerRadius = self.config.hl_backgroundCornerRadius.floatValue; cell.dateLabel.textColor = self.config.hl_textColor; } + if ([self.config.selectedDates containsObject:dateString]) { + cell.backgroundColor = self.config.sel_backgroundColor; + cell.layer.cornerRadius = self.config.sel_backgroundCornerRadius.floatValue; + cell.dateLabel.textColor = self.config.sel_textColor; + } if (date.isToday) { if (![self.config.heightlightDates containsObject:dateString] || diff --git a/ALCalendarPicker/ALCalendarConfig.h b/ALCalendarPicker/ALCalendarConfig.h index 5aa3e3e..a70b0b1 100644 --- a/ALCalendarPicker/ALCalendarConfig.h +++ b/ALCalendarPicker/ALCalendarConfig.h @@ -29,6 +29,9 @@ /** 高亮日期 */ @property (nonatomic, strong) NSArray *heightlightDates; +/** 选择日期 */ +@property (nonatomic, strong) NSArray *selectedDates; + /** 文字颜色 */ @property (nonatomic, strong) UIColor *hl_textColor; @@ -38,4 +41,15 @@ /** 圆角 */ @property (nonatomic, strong) NSNumber *hl_backgroundCornerRadius; +/**** 选中日期 ****/ + +/** 文字颜色 */ +@property (nonatomic, strong) UIColor *sel_textColor; + +/** 背景颜色 */ +@property (nonatomic, strong) UIColor *sel_backgroundColor; + +/** 圆角 */ +@property (nonatomic, strong) NSNumber *sel_backgroundCornerRadius; + @end diff --git a/ALCalendarPicker/ALCalendarPicker.h b/ALCalendarPicker/ALCalendarPicker.h index ec3c504..521b773 100644 --- a/ALCalendarPicker/ALCalendarPicker.h +++ b/ALCalendarPicker/ALCalendarPicker.h @@ -36,6 +36,9 @@ /** 高亮日期 yyyy-MM-dd 格式 */ @property (nonatomic, assign) NSArray *hightLightItems; +/** 选择日期 yyyy-MM-dd 格式 */ +@property (nonatomic, assign) NSArray *selectedItems; + /** 高亮日期优先 当高亮日期与当日日期的重叠的时候优先使用高亮日期的样式 */ @property (nonatomic, assign) BOOL hightlightPriority; @@ -48,4 +51,7 @@ /** 当日日期的样式 */ - (void)setupTodayItemStyle:(void(^)(UIColor **backgroundColor,NSNumber **backgroundCornerRadius,UIColor **titleColor))style; +/** 选择日期的样式 */ +- (void)setupSelectedItemStyle:(void(^)(UIColor **backgroundColor,NSNumber **backgroundCornerRadius,UIColor **titleColor))style; + @end diff --git a/ALCalendarPicker/ALCalendarPicker.m b/ALCalendarPicker/ALCalendarPicker.m index 106908c..b544455 100644 --- a/ALCalendarPicker/ALCalendarPicker.m +++ b/ALCalendarPicker/ALCalendarPicker.m @@ -117,6 +117,25 @@ - (void)setupHightLightItemStyle:(void(^)(UIColor **backgroundColor,NSNumber **b } } +- (void)setupSelectedItemStyle:(void(^)(UIColor **backgroundColor,NSNumber **backgroundCornerRadius,UIColor **titleColor))style +{ + UIColor *backgroundColor; + UIColor *titleColor; + NSNumber *backgroundCornerRadius; + if (style) { + style(&backgroundColor,&backgroundCornerRadius,&titleColor); + } + // 配置高亮样式 + self.config.sel_backgroundColor = backgroundColor; + self.config.sel_textColor = titleColor; + self.config.sel_backgroundCornerRadius = backgroundCornerRadius; + + for (ALCalendarCollectionView *collectionView in self.collectionViews) { + collectionView.config = self.config; + [collectionView reloadData]; + } +} + #pragma mark - Private Method - (void)showLeftCalendar @@ -302,6 +321,13 @@ - (void)setHightLightItems:(NSArray *)hightLightItems [self reloadPicker]; } +- (void)setSelectedItems:(NSArray *)selectedItems +{ + _selectedItems = selectedItems; + self.config.selectedDates = selectedItems; + [self reloadPicker]; +} + - (void)setHightlightPriority:(BOOL)hightlightPriority { _hightlightPriority = hightlightPriority; diff --git a/ALCalendarPickerDemo/ViewController.m b/ALCalendarPickerDemo/ViewController.m index e5a3c00..80b3bf3 100644 --- a/ALCalendarPickerDemo/ViewController.m +++ b/ALCalendarPickerDemo/ViewController.m @@ -20,16 +20,19 @@ @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; - self.view.backgroundColor = [UIColor grayColor]; +// self.view.backgroundColor = [UIColor grayColor]; +} +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; CGSize screenSize = [UIScreen mainScreen].bounds.size; ALCalendarPicker *calP = [[ALCalendarPicker alloc] initWithFrame:CGRectMake(0, 64, screenSize.width, ALPickerHeight)]; calP.delegate = self; // 起始日期 -// calP.beginYearMonth = @"2017-06"; + calP.beginYearMonth = @"2017-01"; // 结束日期 -// calP.endYearMonth = @"2017-11"; + calP.endYearMonth = @"2017-12"; calP.hightLightItems = @[@"2017-06-01",@"2017-05-22",@"2017-06-12"]; calP.hightlightPriority = NO; @@ -47,6 +50,13 @@ - (void)viewDidLoad { *titleColor = [UIColor whiteColor]; }]; + // 选择日期颜色 + [calP setupSelectedItemStyle:^(UIColor *__autoreleasing *backgroundColor, NSNumber *__autoreleasing *backgroundCornerRadius, UIColor *__autoreleasing *titleColor) { + *backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5]; + *backgroundCornerRadius = @(screenSize.width / 20); // 因为宽度是屏幕宽度,宽度 / 10 是cell 宽高 , cell宽高 / 2 为圆形 + *titleColor = [UIColor whiteColor]; + }]; + [self.view addSubview:calP]; } @@ -55,10 +65,10 @@ - (void)calendarPicker:(ALCalendarPicker *)picker didSelectItem:(ALCalendarDate { NSLog(@"%@ %@ %@ %@",picker,date,dateStr,dateObj); - // 动态添加高亮日期 -// NSMutableArray *array = [NSMutableArray arrayWithArray: picker.hightLightItems]; -// [array addObject:dateStr]; -// picker.hightLightItems = array; + // 动态添加选择日期 + NSMutableArray *array = [NSMutableArray arrayWithArray: picker.selectedItems]; + [array addObject:dateStr]; + picker.selectedItems = array; } - (void)didReceiveMemoryWarning { diff --git a/CHANGELOG.md b/CHANGELOG.md index c48d75c..f9595f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. --- +## [1.3.0](https://github.com/Arc-lin/ALCalendarPicker/releases/tag/1.3.0) (10/22/2017) + +#### Update +* 添加了选择日期的样式,点击日期可以添加样式 +* 修复了一些其他的已知问题 + ## [1.2.2](https://github.com/Arc-lin/ALCalendarPicker/releases/tag/1.2.2) (06/20/2017) #### Update diff --git a/README.md b/README.md index d165e50..38c1947 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ 2. 可配置特殊高亮日期(如预约日期),并且可以配置高亮日期背景颜色,文字,背景圆角度数 3. 点击日期代理回调 4. 支持设定起始日期 +5. 支持点击给日期添加选择样式 ### 关于时间区间 @@ -55,6 +56,13 @@ *titleColor = [UIColor whiteColor]; }]; + // 选择日期颜色 + [calP setupSelectedItemStyle:^(UIColor *__autoreleasing *backgroundColor, NSNumber *__autoreleasing *backgroundCornerRadius, UIColor *__autoreleasing *titleColor) { + *backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5]; + *backgroundCornerRadius = @(screenSize.width / 20); // 因为宽度是屏幕宽度,宽度 / 10 是cell 宽高 , cell宽高 / 2 为圆形 + *titleColor = [UIColor whiteColor]; + }]; + [self.view addSubview:calP]; ```