FSCalendar使用和注意事项
相信大家项目中或多或少都有日历这一块的内容吧,公司作为教育行业的软件公司,当然也是一定有的.
最近被日历这一块的内容弄得很头疼啊,改来改去的,不过还是学到了很多东西,至少FSCalendar的使用基本还是熟悉了很多...
1.下面记录一下:
- (FSCalendar *)calendar {
if (!_calendar) {
//日历控件初始化
_calendar = [[FSCalendar alloc] init];
// 设置代理
_calendar.delegate = self;
_calendar.dataSource = self;
_calendar.firstWeekday = ; //设置周一为第一天
_calendar.appearance.weekdayTextColor = [UIColor blackColor];
_calendar.appearance.weekdayFont = FONT_18;
_calendar.appearance.headerTitleColor = [UIColor darkGrayColor];
_calendar.appearance.titleDefaultColor = [UIColor darkGrayColor];
_calendar.appearance.titleFont = FONT_18;
// _calendar.appearance.subtitleDefaultColor = [UIColor greenColor];
_calendar.appearance.eventDefaultColor = [UIColor lightGrayColor];
_calendar.appearance.eventSelectionColor = [UIColor lightGrayColor];
_calendar.appearance.selectionColor = [UIColor redColor];
_calendar.appearance.headerDateFormat = @"yyyy年MM月";
_calendar.appearance.todayColor = [UIColor clearColor];
_calendar.appearance.titleTodayColor = [UIColor lightGrayColor];
_calendar.appearance.borderRadius = 1.0; // 设置当前选择是圆形,0.0是正方形
_calendar.appearance.headerMinimumDissolvedAlpha = 0.0;
_calendar.backgroundColor = [UIColor whiteColor];
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//设置为中文
_calendar.locale = locale; // 设置周次是中文显示
// _calendar.headerHeight = 0.0f; // 当不显示头的时候设置
_calendar.appearance.caseOptions = FSCalendarCaseOptionsWeekdayUsesSingleUpperCase; // 设置周次为一,二
[_calendar selectDate:[NSDate date]]; // 设置默认选中日期是今天
// 设置不能翻页
// _calendar.pagingEnabled = NO;
// _calendar.scrollEnabled = NO;
_calendar.placeholderType = FSCalendarPlaceholderTypeFillHeadTail; //月份模式时,只显示当前月份
}
return _calendar;
}
placeholderType属性需要特别提一下: 这个是月份模式时,只显示当前月份,以前不知道这个属性,因为框架没有更新,测试提出需要不展示六行,日历只需要展示五行. 2.下面介绍下我项目中用到的calendar的代理方法:
#pragma mark - FSCalendarDelegate // 设置五行显示时的calendar布局
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated {
[UIView animateWithDuration:. animations:^{
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
self.myTableView.frame = CGRectMake(, , K_SCREEN_WIDTH, K_SCREEN_HEIGHT);
ScheduleHeaderView *headerView = (ScheduleHeaderView *)[self.myTableView headerViewForSection:];
headerView.frame = calendar.frame;
[self.myTableView reloadData];
} completion:^(BOOL finished) {
}];
NSLog(@"0---%f",calendar.frame.origin.y);
NSLog(@"0---%f",self.myTableView.frame.origin.y);
} // 对有事件的显示一个点,默认是显示三个点
- (NSInteger)calendar:(FSCalendar *)calendar numberOfEventsForDate:(NSDate *)date
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd";
if ([self.datesWithEvent containsObject:[dateFormatter stringFromDate:date]]) {
return ;
}
return ;
} - (void)calendarCurrentPageDidChange:(FSCalendar *)calendar { NSLog(@"calendar.currentPage-- %@",calendar.currentPage);
//日历翻页时记录第一天
// NSDate *changeDate = [calendar tomorrowOfDate:calendar.currentPage];
NSDate *changeDate = calendar.currentPage;
dateStr = [calendar stringFromDate:changeDate format:@"yyyyMMdd"];
//有事件的日期的年和月
NSDateFormatter *formatterYearAndMonth = [[NSDateFormatter alloc] init];
formatterYearAndMonth.dateFormat = @"yyyy-MM";
dateYearAndMonthStr = [formatterYearAndMonth stringFromDate:changeDate];
// 当日
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyy-MM-dd";
NSString *todayDateYearAndMonthStr = [formatterYearAndMonth stringFromDate: [NSDate date]];
// 设置切换到当前月份的时候,显示的是当天的日程
if ([[dateYearAndMonthStr substringWithRange:NSMakeRange(, )] isEqualToString:[todayDateYearAndMonthStr substringWithRange:NSMakeRange(, )]]) {
dateStr = [calendar stringFromDate:[NSDate date] format:@"yyyyMMdd"];
}
[self loadData];
} - (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date {
NSLog(@"did select date %@",[calendar stringFromDate:date format:@"yyyy/MM/dd"]);
dateStr = [calendar stringFromDate:date format:@"yyyyMMdd"];
NSLog(@"---%@",dateStr);
[self loadData];
} - (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date{ return [_datesWithEvent containsObject:[calendar stringFromDate:date format:@"yyyy-MM-dd"]];
}
3.刚开始项目中直接将Calendar作为表视图的头视图,经过测试发现每次切换月份的时候因为改变的calendar的实际高度(因为每月不一定显示是五行或者是六行),再刷新表视图会导致表视图会"闪跳"现象,后面直接将calendar作为表视图的第一个section的headerView就解决了.
#pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return section == ? : self.dataArray.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == ) {
ScheduleCell *cell = [tableView dequeueReusableCellWithIdentifier:MyScheduleCellIdentify forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (self.dataArray.count > ) {
cell.myApplyModel = self.dataArray[indexPath.row];
}
return cell;
} else {
return nil;
}
} #pragma mark - UITableViewDelegate - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (section == ) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(, , K_SCREEN_WIDTH, )];
[view addSubview:self.calendar];
self.calendar.frame = CGRectMake(, , K_SCREEN_WIDTH, );
return view;
} else {
ScheduleHeaderView *sectionHeaderView = [[ScheduleHeaderView alloc]initWithFrame:CGRectMake(, , K_SCREEN_WIDTH, )];
sectionHeaderView.titleLabel.text = @"今日会议";
sectionHeaderView.titleLabel.font = FONT_18;
sectionHeaderView.badgeLabel.text = [NSString stringWithFormat:@"%ld",(unsigned long)self.dataArray.count];
return sectionHeaderView;
}
return nil;
} - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == ) {
return self.calendar.frame.size.height ? : ;
} else { return ;
}
} - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.001f;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == ) {
return [tableView fd_heightForCellWithIdentifier:MyScheduleCellIdentify configuration:^(ScheduleCell *cell) {
cell.myApplyModel = self.dataArray[indexPath.row];
}];
} else {
return ;
}
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES]; }
总结:
1.刚开始觉得一个Calendar展示没啥问题,毕竟有成熟的第三方FSCalendar嘛,实际动手才发现很多问题需要注意;
2.完成项目的一个功能的时候,不要想着有第三方的支持,直接用就好了,实际上还是要多看看作者的demo,熟悉框架的实现才能很好的用到项目中;
3.遇到问题,多想想可能造成的原因,多尝试用不同的方法实现,说不定就解决了当前的bug问题.
4.空闲时间还是要多学学优秀的第三方框架,不能只停留在用的层面,想想实现和调用的原理,为什么要这个属性,为什么要实现这个方法,为什么要调用这个代理.
多学习,爱学习的孩纸运气不会太差,加油!!
FSCalendar使用和注意事项的更多相关文章
- jQuery UI resizable使用注意事项、实时等比例拉伸及你不知道的技巧
这篇文章总结的是我在使用resizable插件的过程中,遇到的问题及变通应用的奇思妙想. 一.resizable使用注意事项 以下是我在jsfiddle上写的测试demo:http://jsfiddl ...
- Windows Server 2012 NIC Teaming介绍及注意事项
Windows Server 2012 NIC Teaming介绍及注意事项 转载自:http://www.it165.net/os/html/201303/4799.html Windows Ser ...
- TODO:Golang指针使用注意事项
TODO:Golang指针使用注意事项 先来看简单的例子1: 输出: 1 1 例子2: 输出: 1 3 例子1是使用值传递,Add方法不会做任何改变:例子2是使用指针传递,会改变地址,从而改变地址. ...
- app开发外包注意事项,2017最新资讯
我们见过很多创业者,栽在这app外包上.很多创业者对于app外包这件事情不是特别重视,以为将事情交给app外包公司就完事了,实际上不是的.无论是从选择app外包公司还是签订合同.售后维护等各方面都有许 ...
- favicon.ioc使用以及注意事项
1.效果 2.使用引入方法 2.1 注意事项:(把图标命名为favicon.ico,并且放在根目录下,同时使用Link标签,多重保险) 浏览器默认使用根目录下的favicon.ico 图标(如果你并没 ...
- ORACLE分区表梳理系列(二)- 分区表日常维护及注意事项(红字需要留意)
版权声明:本文发布于http://www.cnblogs.com/yumiko/,版权由Yumiko_sunny所有,欢迎转载.转载时,请在文章明显位置注明原文链接.若在未经作者同意的情况下,将本文内 ...
- 【原】Masonry+UIScrollView的使用注意事项
[原]Masonry+UIScrollView的使用注意事项 本文转载请注明出处 —— polobymulberry-博客园 1.问题描述 我想实现的使用在一个UIScrollView依次添加三个UI ...
- 《连载 | 物联网框架ServerSuperIO教程》- 5.轮询通讯模式开发及注意事项。附:网友制作的类库说明(CHM)
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
- 《连载 | 物联网框架ServerSuperIO教程》- 6.并发通讯模式开发及注意事项
1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...
随机推荐
- Codeforces 1082 毛毛虫图构造&最大权闭合子图
A #include<bits/stdc++.h> using namespace std; typedef long long ll; , MAXM = ; //int to[MAXM ...
- lib异步中断
基于libusbx-1.0.18-rc1,libusbx现已重新merage到libusb.1. 初始化使用libusb_init初始化libusb,如果是单设备通信,ctx参数可以传NULL,表示使 ...
- solr 数据库关联,表数据添加不进solr,一直indexing
id没有映射,数据库表字段没有id,要把其中一字段映射为id
- mysql 命令行导出导入数据
导出数据库(sql脚本) mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u root -p --databases db_name > test ...
- 前端每周清单第 49 期:Webpack 4 Beta 尝鲜,React Windowing 与 setState 分析,Web Worker 实战
前端每周清单专注前端领域内容,以对外文资料的搜集为主,帮助开发者了解一周前端热点:分为新闻热点.开发教程.工程实践.深度阅读.开源项目.巅峰人生等栏目.欢迎关注[前端之巅]微信公众号(ID: fron ...
- ${filename}用法二:
假设:filename=/dir1/dir2/dir3/my.filename.txt 1.单一符号是最小匹配﹔两个符号是最大匹配. ${filename::}:提取最左边的5个字节:/dir1 ${ ...
- Hadoop-No.7之行键
和哈希表类比,HBase中的行键类似于哈希表中的键.要构造一个良好的HBase模式,关键之一就是选择一个合适的行键. 1 记录检索 行键是HBase中检索记录所使用的键.HBase记录含有的列在数量上 ...
- 服务消费(LoadBalancerClient、Ribbon、Feign)
转自:https://www.jianshu.com/p/562045489d9d 4.1使用LoadBalancerClient 在Spring Cloud Commons中提供了大量的与服务治理相 ...
- Python入门-2编程基本概念:03引用的本质-栈内存和堆内存-内存示意图
引用 在Python中,变量也称为:对象的引用.因为,变量存储的就是对象的地址. 变量通过地址引用了“对象”. 变量位于:栈内存(压栈出栈等细节,后续再介绍). 对象位于:堆内存. Python是动态 ...
- DOM 事件流与事件处理程序
㈠事件流 ▶事件:是文档和浏览器窗口中发生的,特定的交互瞬间. ▶事件流:描述的是从页面中接受事件的顺序 ⑴DOM事件冒泡 定义:事件最开始由最具体的元素(文档中嵌套层次最深的那个节点)接受,然后 ...