iOS 日历 签到功能
公司APP涉及到签到功能,具体以当前日期为分界线。
也就是今天之前的日期分为已签到和未签到并且未签到可以补签(涉及到3种UI效果)。今天分为已签到和未签到(2种UI效果),今天以后的显示为日期(1种UI效果)。
下面是效果图奉上。
红色部分为组头,显示的是当前年月。
绿色部分是当前月份的日期以及之前的日期。
数字部分为当前日期后面的日期。
这样就可以自定义出来今天日期之前的日期是否签到。
下面是具体代码实现。
直接新建工程,在新工程的viewcontroller.m里面直接拷贝如下代码:
#import "ViewController.h"
#import "NSDate+LYWCalendar.h"
#import "LYWCollectionViewCell.h"
#import "LYWCollectionReusableView.h"
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define NumberMounthes 1
@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>{
//自动布局
UICollectionViewFlowLayout *_layout;
//表格视图
UICollectionView *_collectionView;
//当月第一天星期几
NSInteger firstDayInMounthInWeekly;
NSMutableArray *_firstMounth;
NSMutableArray *_dateArray;
}
@end
static NSString *cellID =@"cellID";
static NSString *headerID =@"headerID";
static NSString *footerID =@"footerID";
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.automaticallyAdjustsScrollViewInsets =NO;//关闭自动适应
NSArray *weekTitleArray =@[@"日",@"一",@"二",@"三",@"四",@"五",@"六"];
for (int i =0; i < weekTitleArray.count; i++) {
UILabel *weekTitleLable = [[UILabelalloc]initWithFrame:CGRectMake(i * ((ScreenWidth/(weekTitleArray.count))),64,ScreenWidth/(weekTitleArray.count ),30)];
if (i ==0 || i ==6) {
weekTitleLable.textColor = [UIColorblackColor];
}else{
weekTitleLable.textColor = [UIColorblackColor];
}
weekTitleLable.text = [weekTitleArrayobjectAtIndex:i];
weekTitleLable.textAlignment =NSTextAlignmentCenter;
[self.viewaddSubview:weekTitleLable];
}
[selfcreateData];
[selfcreateCollectionView];
}
-(void)createCollectionView{
//设置collectionView及自动布局,代理方法尤为重要
_layout = [[UICollectionViewFlowLayoutalloc]init];
//头部始终在顶端
_layout.sectionHeadersPinToVisibleBounds =YES;
//头部视图高度
_layout.headerReferenceSize =CGSizeMake(414,40);
_layout.minimumLineSpacing =0;
_layout.minimumInteritemSpacing =0;
_collectionView = [[UICollectionViewalloc]initWithFrame:CGRectMake(0,64 + 30, ScreenWidth,ScreenHeight -64 -30)collectionViewLayout:_layout];
_collectionView.backgroundColor = [UIColorwhiteColor];
//注册表格
[_collectionViewregisterClass:[LYWCollectionViewCellclass]forCellWithReuseIdentifier:cellID];
//