iOS 封装日历表

作者: 土鳖不土 | 来源:发表于2015-10-07 19:03 被阅读1708次

不多说先上图:

需求结构图

如上效果图所示
第一个红框一个view就搞定。
第二个红框想到主要控件就是用UICollectionView。每个分为两个section,section0数据一个数组就OK了。

接下来重点分析下section1的数据

今天是哪一天

- (NSInteger)day:(NSDate *)date{
    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
    return [components day];
}

第本月是第几个月

- (NSInteger)month:(NSDate *)date{
    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
    return [components month];
}

今年是哪一年年份

- (NSInteger)year:(NSDate *)date{
    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
    return [components year];
}

这个月有几天

- (NSInteger)totaldaysInMonth:(NSDate *)date{
    NSRange daysInLastMonth = [[NSCalendar currentCalendar] rangeOfUnit:NSCalendarUnitDay inUnit:NSCalendarUnitMonth forDate:date];
    return daysInLastMonth.length;
}
日历表效果

demo地址:https://github.com/tubie/JFCalendarPicker

屏幕快照 2015-10-07 18.58.48.png

如果你觉得还不错可以给我一个小星星。我会很开心的。
有什么问题我会一一解答。

注:本demo的设计思路参考是一个千皇89的的简友

相关文章

网友评论

  • RiberWang:不错
  • 金康帅:学习了,感谢 :smile:
    金康帅:@tubiebutu 我只是重新打了一遍,才学了5个月,最近在观看别人源码,主要是自己重新打一遍。 :smile: 微信:jksdzh
    土鳖不土:@金康帅 哈哈,相互学习。你微信号多少,我加下你的微信
  • 一抹相思泪成雨:我想问下 怎么写日历 开始不空格 直接把上个月的日期填写到本月 如果点击上个月日期 自动滚动到上个月。。

本文标题:iOS 封装日历表

本文链接:https://www.haomeiwen.com/subject/acqncttx.html