I am using an FSCalendar in my project and I am wondering how to make my calendar scale to a new height that is being animated? I have an "eventsView" that is being swiped up and down and when I change the height of my calendar, the white border line that marks the edge of the calendar changes but the dates aren't scaling to take up the entire space given whether that be bigger or smaller than after the view loads. Any help would be great, I am working in swift 3, and the fscalendar framework installed via cocoa pods.
How do I scale the height of FSCalendar?
4.3k views Asked by Gaard Anderson AtThere are 2 answers
Solution
There is solution to accomplish resizing height of FSCalendar view.
(Tested on version 2.8.4)
In UIViewController which contains FSCalendar view do following steps:
Add variable for FSCalendar view's height constraint:
private var calendarHeight: NSLayoutConstraint?
Configure initial constraint f.ex. in
viewDidLoad()
:calendarHeight = calendar.heightAnchor.constraint(equalToConstant: 280) calendarHeight?.isActive = true
Important: value which I used as height 280.0
has influence on its subviews layout. Presented value is working best for me. I assume that it's connected with default height for calendar view and based on that all other subviews are laid out.
Add FSCalendarDelegate function implementation like below:
func calendar(_ calendar: FSCalendar, boundingRectWillChange bounds: CGRect, animated: Bool) { calendarHeight?.constant = bounds.height view.layoutIfNeeded() }
Remember to add self as delegate provider, f.ex. in
viewDidLoad()
:calendar.delegate = self
To sum up, we create constraint which is holding calendar view height based on bounding rect calculated by FSCalendar and returning after each change.
Ok it's ridiculous and wrong, but this is the only way I could find how to set height in the half an hour after I should've been home, without changing the library.
If someone knows a better way please do let us know.