'FSCalendar - Custom HeaderView, WeekDayView
I am using FSCalendar in my project and I want to achieve a custom appearence of calendar. I read the documentation and looked for the answer on stackoverflow but still cannot find the answer.
Is it possible to customize HeaderView (displayed month) or WeekDaysView (labels of weekdays) without editing existing FSCalendar code? For example HeaderView would contain buttons or WeekDaysView would have borders?
I guess this is possible by editing directly FSCalendar code but the problem is that it is programmed in Objective-C (since I am not really familiar with Obj-C I am looking for a swift solution). I also read some tips that it can be done by overlapping custom views but it does not seem right to me.
Is there a way to customize these views in swift? Is it possible to do so as it may be done with Custom Cell, when it can be a subclass of FSCalendarCell? (There is no need to change existing FSCalendar library code). How do people customize FSCalendar? There are tons of projects which use this framework and have completely custom styles.
Solution 1:[1]
let vwHead = FSCalendarHeaderView()
vwHead.backgroundColor = .DarkBlue
self.calendar.calendarHeaderView = vwHead
and you can customize header of Calender Accordingly
Solution 2:[2]
As a new user of FScalendar, I am hoping my belated could be of assistance.
option 1
It is clear that FScalendar does have "limited" features as shown below. You can download FSCalendar github file and look into FSCalendarAppearance, FSCalendarHeaderView.
option 2
Above answer's solution would have worked. If this was the case. But if you want to add a button, you have to create a separate class of FSCalendarCell and connect them to your calendar.
self.calendar.calendarHeaderView.backgroundColor = .systemBlue
option 3
If that's too much work, you can simply create an overlapping UIbutton or view (on top of the calendarView) to create custom method that will trigger FSCalendar Delegate methods.
Solution 3:[3]
You do this with the help of event handlers. Here's a basic sampler to get you started.
In the event handler, you capture the target element's id, or any other information available. Add console.log(this) or console.log(e.target) (synonymous) to your code to understand what data is captured with a click event. Then generate a timestamp, and add the info to your log. Here we just dump the log at each event, you'd probably want to do something more.
// Log click events into an array
let clickLog = [];
// Element for dumping out the log
let loggerElement = document.querySelector('#log');
// Log dumper (adapt for your use case)
function iterateLog() {
loggerElement.innerHTML = '';
for(const clickData of clickLog) {
loggerElement.insertAdjacentHTML('afterbegin', `${clickData[0]}: ${clickData[1]}\n`);
}
}
// Let's select all <td> elements:
let tdList = document.querySelectorAll('td');
// And then attach click event handlers:
for(const td of tdList) {
td.addEventListener('click', function(e) {
// Logging: [ parentElement.id, timestamp ]
clickLog.push([this.parentElement.id, new Date().valueOf()]);
// And write it out right away, for purposes of this demo:
iterateLog();
});
}
<table>
<tr id="a"><td>alpha</td></tr>
<tr id="b"><td>beta</td></tr>
<tr id="g"><td>gamma</td></tr>
<tr id="d"><td>delta</td></tr>
</table>
<pre id="log"></pre>
You will not be able to save it as a CSV file directly from Javascript though. Either pass it with AJAX to a server-end PHP script for saving -- or provide a download on the fly, and save it yourself. (How to implement either of these options is beyond this post.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Noor Ahmed Natali |
| Solution 2 | Michael |
| Solution 3 |


