Skip to content

Commit

Permalink
修改文件结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Arc-lin committed Jun 19, 2017
1 parent b0e65a6 commit cd7b3f6
Show file tree
Hide file tree
Showing 18 changed files with 1,127 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ALCalendarPicker/ALCalendarCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ALCalendarCell.h
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/16.
// Copyright © 2017年 arclin. All rights reserved.
//

#import <UIKit/UIKit.h>

@class ALCalendarDate;

@interface ALCalendarCell : UICollectionViewCell

@property (nonatomic, strong) ALCalendarDate *date;

/** 星期 */
@property (nonatomic, copy) NSString *weekDay;

@property (nonatomic, strong, readonly) UILabel *dateLabel;

@end
79 changes: 79 additions & 0 deletions ALCalendarPicker/ALCalendarCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//
// ALCalendarCell.m
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/16.
// Copyright © 2017年 arclin. All rights reserved.
//

#import "ALCalendarCell.h"

#import "ALCalendarDate.h"

#import <Masonry/Masonry.h>

#define KLightGrayColor [UIColor colorWithRed:127.0/255.0 green:143.0/255.0 blue:164.0/255.0 alpha:1]

#define KDarkGrayColor [UIColor colorWithRed:44.0/255.0 green:49.0/255.0 blue:53.0/255.0 alpha:1]

@interface ALCalendarCell()

@property (nonatomic, strong) UILabel *dateLabel;

@end

@implementation ALCalendarCell

- (instancetype)initWithFrame:(CGRect)frame
{
if(self = [super initWithFrame:frame]) {
[self setupView];
}
return self;
}

- (void)setupView
{
[self addSubview:self.dateLabel];

self.layer.cornerRadius = 5.0f;

__weak typeof(self) weakSelf = self;
[self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(weakSelf.mas_centerX);
make.centerY.equalTo(weakSelf.mas_centerY);
}];
}

- (void)setDate:(ALCalendarDate *)date
{
_date = date;
if (date.notThisMonth) {
self.backgroundColor = [UIColor whiteColor];
self.dateLabel.textColor = KLightGrayColor;
} else {
self.backgroundColor = [UIColor whiteColor];
self.dateLabel.textColor = KDarkGrayColor;
}
self.dateLabel.text = date.date;
}

- (void)setWeekDay:(NSString *)weekDay
{
_weekDay = weekDay;
self.dateLabel.text = weekDay;
self.dateLabel.textColor = KLightGrayColor;
}

- (UILabel *)dateLabel
{
if (!_dateLabel) {
_dateLabel = [[UILabel alloc] init];
_dateLabel.textColor = KDarkGrayColor;
_dateLabel.font = [UIFont systemFontOfSize:14];
}
return _dateLabel;
}


@end
33 changes: 33 additions & 0 deletions ALCalendarPicker/ALCalendarCollectionView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// ALCalendarCollectionView.h
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/16.
// Copyright © 2017年 arclin. All rights reserved.
//

#import <UIKit/UIKit.h>

@class ALCalendarDate,ALCalendarCollectionView,ALCalendarConfig;

@protocol ALCalendarCollectionViewDelegate <NSObject>

/**
* 点击了某个日期
*/
- (void)calendarView:(ALCalendarCollectionView *)calendarCollectionView didSelectItem:(ALCalendarDate *)date dateString:(NSString *)dateString;

@end

@interface ALCalendarCollectionView : UICollectionView

/** 当前的年份和月份 yyyy-MM */
@property (nonatomic, copy) NSString *yearAndMonth;

/** 代理 */
@property (nonatomic, assign) id<ALCalendarCollectionViewDelegate> collectionViewDelegate;

/** 配置 */
@property (nonatomic, strong) ALCalendarConfig *config;

@end
133 changes: 133 additions & 0 deletions ALCalendarPicker/ALCalendarCollectionView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//
// ALCalendarCollectionView.m
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/16.
// Copyright © 2017年 arclin. All rights reserved.
//

#import "ALCalendarCollectionView.h"

#import "ALCalendarCell.h"

#import "ALCalendarDate.h"
#import "ALCalendarHelper.h"
#import "ALCalendarConfig.h"

#import "UIView+Frame.h"

@interface ALCalendarCollectionView()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) NSArray *titles;

@property (nonatomic, strong) NSArray *dates;

@end

@implementation ALCalendarCollectionView

static NSString *identifier = @"dateCell";

- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UICollectionViewLayout *)layout
{
if (self = [super initWithFrame:frame collectionViewLayout:layout]) {
self.dataSource = self;
self.delegate = self;
self.contentInset = UIEdgeInsetsMake(5, 20, 0, 20);
self.backgroundColor = [UIColor whiteColor];
[self registerClass:[ALCalendarCell class] forCellWithReuseIdentifier:identifier];
}
return self;
}

#pragma mark - UICollectionDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 2;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
if (section == 0) return 7;
return self.dates.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ALCalendarCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];

if(indexPath.section == 0) {
cell.weekDay = self.titles[indexPath.row];
} else {
ALCalendarDate *date = self.dates[indexPath.row];
cell.date = date;

/** 当前显示的日期 */
NSString *currentDate = [self.yearAndMonth stringByAppendingFormat:@"-%02zd",date.date.integerValue];

if ([self.config.heightlightDates containsObject:currentDate]) {
cell.backgroundColor = self.config.hl_backgroundColor;
cell.layer.cornerRadius = self.config.hl_backgroundCornerRadius.floatValue;
cell.dateLabel.textColor = self.config.hl_textColor;
}

if (date.isToday) {
if (![self.config.heightlightDates containsObject:currentDate] ||
([self.config.heightlightDates containsObject:currentDate] && !self.config.hightlightPriority)) {
cell.backgroundColor = self.config.tod_backgroundColor;
cell.layer.cornerRadius = self.config.tod_backgroundCornerRadius.floatValue;
cell.dateLabel.textColor = self.config.tod_textColor;
}
}
}
return cell;
}

#pragma mark - UICollectionDelegate

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
if ([self.collectionViewDelegate respondsToSelector:@selector(calendarView:didSelectItem:dateString:)]) {
ALCalendarDate *date = self.dates[indexPath.row];
[self.collectionViewDelegate calendarView:self didSelectItem:date dateString:[self.yearAndMonth stringByAppendingFormat:@"-%02zd",date.date.integerValue]];
}
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(self.width / 10, self.width / 10);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
return 10;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 10;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(5, 0, 5, 0);
}

#pragma mark - setter & getter

- (NSArray *)titles
{
return @[@"",@"",@"",@"",@"",@"",@""];
}

- (void)setYearAndMonth:(NSString *)yearAndMonth
{
_yearAndMonth = yearAndMonth;
if (yearAndMonth) {
_dates = [ALCalendarHelper datesWithYearAndMonth:yearAndMonth];
[self reloadData];
}
}

@end
41 changes: 41 additions & 0 deletions ALCalendarPicker/ALCalendarConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// ALCalendarConfig.h
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/17.
// Copyright © 2017年 arclin. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ALCalendarConfig : NSObject

/** 当前日期优先 */
@property (nonatomic, assign) BOOL hightlightPriority;

/**** 今天日期 *****/

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

/** 背景颜色 */
@property (nonatomic, strong) UIColor *tod_backgroundColor;

/** 圆角 */
@property (nonatomic, strong) NSNumber *tod_backgroundCornerRadius;

/**** 高亮日期 ****/

/** 高亮日期 */
@property (nonatomic, strong) NSArray<NSString *> *heightlightDates;

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

/** 背景颜色 */
@property (nonatomic, strong) UIColor *hl_backgroundColor;

/** 圆角 */
@property (nonatomic, strong) NSNumber *hl_backgroundCornerRadius;

@end
13 changes: 13 additions & 0 deletions ALCalendarPicker/ALCalendarConfig.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ALCalendarConfig.m
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/17.
// Copyright © 2017年 arclin. All rights reserved.
//

#import "ALCalendarConfig.h"

@implementation ALCalendarConfig

@end
24 changes: 24 additions & 0 deletions ALCalendarPicker/ALCalendarDate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ALCalendarDate.h
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/17.
// Copyright © 2017年 arclin. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface ALCalendarDate : NSObject

/** 日期(号数) */
@property (nonatomic, copy) NSString *date;

/** 不是这个月 */
@property (nonatomic, assign) BOOL notThisMonth;

/** 是今天 */
@property (nonatomic, assign) BOOL isToday;

+ (instancetype)dateWith:(NSString *)dateStr isNotThisMonth:(BOOL)notThisMonth;

@end
21 changes: 21 additions & 0 deletions ALCalendarPicker/ALCalendarDate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// ALCalendarDate.m
// ALCalendarPickerDemo
//
// Created by Arclin on 2017/6/17.
// Copyright © 2017年 arclin. All rights reserved.
//

#import "ALCalendarDate.h"

@implementation ALCalendarDate

+ (instancetype)dateWith:(NSString *)dateStr isNotThisMonth:(BOOL)notThisMonth
{
ALCalendarDate *date = [[ALCalendarDate alloc] init];
date.date = dateStr;
date.notThisMonth = notThisMonth;
return date;
}

@end
Loading

0 comments on commit cd7b3f6

Please sign in to comment.