Reputation: 4222
I am using FSCalendar to implement a custom calendar. I managed to make something similar to the following by changing a few methods and handling the various select and deselect modes.
Here is a screenshot of what I have so far:
Now the designer wants a different color for all the dates lying between the initial and final date. Example: Apart from 13th March and 22nd March in the screenshot, all the dates should be a different color.
How do I go about changing the color of the dates inside the range excluding the final and initial values?
Or
If someone could suggest another project/pod that will create a similar UI to the screenshot above and satisfy the color requirements, that also works!
Upvotes: 3
Views: 3722
Reputation: 4222
If anyone wants to know how i went around doing this, I had to setup new BOOL
properties inside each cell, to keep track of wether the cell is the first, last or lies within the range. And then call the configureCell
function provided in the pod and setup different colors based on the BOOL
values at appropriate places. Inside the FSCalendarCell
configureAppearance
:
if (self.isCellInsideDateRange){
cellFillColor = [self colorFromHexString:mainDictionary[@"calendarLightColor"]].CGColor;
}else if(self.isCellFirstCell || self.isCellLastCell){
cellFillColor = [self colorFromHexString:mainDictionary[@"calendarDarkColor"]].CGColor;
}else{
cellFillColor = [UIColor whiteColor].CGColor;
}
And inside FSCalendar.m
inside each cellForItemAtIndexPath
check wether the date inside the cell lies within the range of selected dates and set the appropriate BOOL
values to true
or false
I'll admit it required quite a lot of handling on my part and even then i wasn't able to resolve some crashes that started occurring due to cell re-use and it being unable to deque re-usable cells. Most probably caused by the combination of handling i had to do to handle various app specific cases, adding new properties and the time the cell color animations take to appear.
In the end i used the JTAppleCalendar that offers quite a lot of customization albeit no animation but its a small thing when compared to the customization capabilities.
Upvotes: 2