使用FSCalendar仅显示该月份提到的范围内的日期 [英] Show only dates in the mentioned range for the month using FSCalendar

查看:751
本文介绍了使用FSCalendar仅显示该月份提到的范围内的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FSCalendar 。我可以实现除以下几点以外的所有功能:

I am using FSCalendar. I am able to achieve everything except below point:

1)我要删除集合视图中不在日历范围内的日期。例如我的日历日期从当前日期到当前日期为止的过去30天。在今天的情况下,从 4月20日到5月21日。因此,我不想显示4月1日至19日以及5月22日至5月底的日期。对于我来说,完成该库中编写的逻辑有点复杂。

1) I want to remove dates for the collection view which are not in the range of the calendar. For Eg. My calendar date ranges from the current date to the past 30 days from the current date. In today's scenario from 20th April to the 21st of May. So, I don't want to show dates from 1st to 19th of April and 22nd to the month end of May. The logic written in the library is a bit complicated for me to get it done.

我已经共享了GitHub链接,以便代码签出并可能帮助我。我没有共享任何代码,因为它不是单个文件更改,而是包含多个文件,这也是为什么我共享库回购链接的原因。任何帮助将不胜感激。

I have already shared the GitHub link for the code to check out and maybe help me. I haven't shared any of my code as it is not a single file change that is needed, it includes multiple files, and that why I shared the link to the library repo. Any help would be appreciated.

推荐答案

在FSCalendar中的代码中探索了更多细节之后,我认为您可以做到。但这意味着您必须对库进行一些更改。
首先是 FSCalendarExtension

After exploring more detail in code in FSCalendar, I figure that you can do it. But it's mean you have to make some changes for the library. First in FSCalendarExtension,

- (nullable NSDate *)fs_firstDayOfMonth:(NSDate *)month
{
    if (!month) return nil;
    NSDateComponents *components = [self components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour fromDate:month];
    components.day = today;
    return [self dateFromComponents:components];
}

这将是本月的第一天,您必须重新设置到当前日期。以及修改以下所有功能:

This will get the first day of the month, you have to set it back to the current date. As well as modified all the following functions :

- (nullable NSDate *)fs_firstDayOfWeek:(NSDate *)week
- (nullable NSDate *)fs_lastDayOfWeek:(NSDate *)week
- (NSInteger)fs_numberOfDaysInMonth:(NSDate *)month

我的意思是很多变化。而且,您必须更改库的代码,一种更好的方法是创建自己的日历。会更好。

I mean that's a lot of changes. And you have to change code for library, A better way for you is creating your own calendar. It would be better.

这篇关于使用FSCalendar仅显示该月份提到的范围内的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆