Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
143 views
in Technique[技术] by (71.8m points)

ios - Show only dates in the mentioned range for the month using FSCalendar

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

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...