Skip to content

Commit

Permalink
修改bug,添加选择样式
Browse files Browse the repository at this point in the history
  • Loading branch information
Arclin committed Oct 22, 2017
1 parent ca34a95 commit f31fe05
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 12 deletions.
11 changes: 6 additions & 5 deletions ALCalendarPicker.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions ALCalendarPicker/ALCalendarCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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] ||
Expand Down
14 changes: 14 additions & 0 deletions ALCalendarPicker/ALCalendarConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
/** 高亮日期 */
@property (nonatomic, strong) NSArray<NSString *> *heightlightDates;

/** 选择日期 */
@property (nonatomic, strong) NSArray<NSString *> *selectedDates;

/** 文字颜色 */
@property (nonatomic, strong) UIColor *hl_textColor;

Expand All @@ -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
6 changes: 6 additions & 0 deletions ALCalendarPicker/ALCalendarPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
/** 高亮日期 yyyy-MM-dd 格式 */
@property (nonatomic, assign) NSArray<NSString *> *hightLightItems;

/** 选择日期 yyyy-MM-dd 格式 */
@property (nonatomic, assign) NSArray<NSString *> *selectedItems;

/** 高亮日期优先 当高亮日期与当日日期的重叠的时候优先使用高亮日期的样式 */
@property (nonatomic, assign) BOOL hightlightPriority;

Expand All @@ -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
26 changes: 26 additions & 0 deletions ALCalendarPicker/ALCalendarPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -302,6 +321,13 @@ - (void)setHightLightItems:(NSArray<NSString *> *)hightLightItems
[self reloadPicker];
}

- (void)setSelectedItems:(NSArray<NSString *> *)selectedItems
{
_selectedItems = selectedItems;
self.config.selectedDates = selectedItems;
[self reloadPicker];
}

- (void)setHightlightPriority:(BOOL)hightlightPriority
{
_hightlightPriority = hightlightPriority;
Expand Down
24 changes: 17 additions & 7 deletions ALCalendarPickerDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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];

}
Expand All @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
2. 可配置特殊高亮日期(如预约日期),并且可以配置高亮日期背景颜色,文字,背景圆角度数
3. 点击日期代理回调
4. 支持设定起始日期
5. 支持点击给日期添加选择样式

### 关于时间区间

Expand Down Expand Up @@ -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];
```

Expand Down

0 comments on commit f31fe05

Please sign in to comment.