I am using FSCalendar https://github.com/WenchaoIOS/FSCalendar I have a button in my VC and FSCalendar in UIView If I click on the button I need to show the Current date(something like the google calendar app) how can I do this?
Asked
Active
Viewed 1.4k times
4 Answers
1
You can call the calendar selectDate with today's date in the button action. like below:
NSDate *today = [NSDate date];
[calendar setDate: today];
When you tap the button this will scroll to today with animation and select it.
I hope this helps.

Ismail
- 2,778
- 2
- 24
- 39
-
I have 2 arrays as - eventDateArray consisting event NSDates & another array as colouredDateArray having NSDate's to be coloured. How can I achieve the same ? Please reply. https://github.com/WenchaoD/FSCalendar/issues/275 – Kamala Dash Apr 20 '16 at 13:35
1
If you want to show the month of today.
calendar.currentPage = [NSDate date];
If you want to 'select' today and show the month of today
[calendar selectDate:[NSDate date]];

WenchaoD
- 136
- 3
- 5
-
I have 2 arrays as - eventDateArray consisting event NSDates & another array as colouredDateArray having NSDate's to be coloured. How can I achieve the same ? Please reply. https://github.com/WenchaoD/FSCalendar/issues/275 – Kamala Dash Apr 20 '16 at 13:34
-
Hello, I want to remove the dates out of range for the current month in the same FSCalendar. For eg - date range is 21st May to 20 June, so I want to show the calendar only for these dates. Is it possible with the library? I would be happy to post another question for this to answer but was curious if it possible quickly? – mAc May 21 '20 at 06:19
-
Link To my question: https://stackoverflow.com/questions/61928955/show-only-dates-in-the-mentioned-range-for-the-month-using-fscalendar – mAc May 21 '20 at 10:05
1
Button Action:
- (void)backToToday {
// scroll to page date
self.currentPageDate = self.today;
// default selected date
self.selectedDate = self.today;
self.calendar.currentPage = self.currentPageDate;
[self.calendar selectDate:self.selectedDate scrollToDate:NO];
}

Qun Li
- 1,256
- 13
- 13
-
Can you please help me also with my question? Link To my question: https://stackoverflow.com/questions/61928955/show-only-dates-in-the-mentioned-range-for-the-month-using-fscalendar – mAc May 21 '20 at 10:06
0
Create FSCalendar Programmatically and Customise
var calendar: FSCalendar!
override func viewDidLoad() {
calendar = FSCalendar(frame: CGRect(x: 0, y: 0, width: self.calendarView.frame.width, height: self.calendarView.frame.height))
calendar.alpha = 1
calendar.center = calendarView.center
calendar.headerHeight = 0
calendar.placeholderType = .none
calendar.appearance.weekdayTextColor = .lightGray // weekday text color
calendar.appearance.titleDefaultColor = .white // active dates color
calendar.appearance.titleSelectionColor = .black // selected date text color
calendar.appearance.titleTodayColor = .black // todays date text color
calendar.appearance.todayColor = .white // todays date circle color
calendar.appearance.selectionColor = .lightGray // date selection color
calendarView.addSubview(calendar)
calendarCurrentPageDidChange(calendar)
}
To display current month name from FSCalendar
func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
let currentPageDate = calendar.currentPage
let month = Calendar.current.component(.month, from: currentPageDate)
let monthName = DateFormatter().monthSymbols[month - 1].capitalized // Get current month name to display separately
monthLbl.setTitle(monthName, for: .normal)
}
FSCalendar Delegate functions
func maximumDate(for calendar: FSCalendar) -> Date {
var dateComponents:DateComponents = DateComponents()
dateComponents.month = 12 // maximum month to display in calendar
let currentCalander:Calendar = Calendar.current
return currentCalander.date(byAdding:dateComponents, to: Date())!
}
func minimumDate(for calendar: FSCalendar) -> Date {
var dateComponents:DateComponents = DateComponents()
dateComponents.month = 0 // minimum month to display in calendar
let currentCalander:Calendar = Calendar.current
return currentCalander.date(byAdding:dateComponents, to: Date())!
}
func calendar(_ calendar: FSCalendar, didSelect date: Date, at monthPosition: FSCalendarMonthPosition) {
self.scrollToDate(date.date)
}
Event list using FSCalendar - Show and Hide Calendar using UIButton

khirish
- 537
- 1
- 7
- 9