- Objective - c
_calendar.scrollDirection = FSCalendarScrollDirectionVertical;
- Swift
calendar.scrollDirection = .vertical
- Objective - c
_calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default
- Swift
calendar.scrollDirection = .Horizontal
- There are cases such as
Changing Scope
、Changing month while showsPlaceholders is false
will trigger a bounds changing of FSCalendar, make sure the frame is adjusted in-calendar:boundingRectWillChange:animated:
// For autoLayout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
_calendarHeightConstraint.constant = CGRectGetHeight(bounds);
[self.view layoutIfNeeded];
}
// For manual layout
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
calendar.frame = (CGRect){calendar.frame.origin,bounds.size};
}
- Objective-C
_calendar.scope = FSCalendarScopeWeek;
- Swift
calendar.scope = .week
- Objective - c
_calendar.scope = FSCalendarScopeMonth; // By default
- Swift
calendar.scope = .month
- Objective-C
calendar.allowsMultipleSelection = YES;
- Swift
calendar.allowsMultipleSelection = true;
- Objective-C
_calendar.firstWeekday = 2;
- Swift
calendar.firstWeekday = 2
- Objective-C
calendar.appearance.headerDateFormat = @"MMM yy";
- Swift
calendar.appearance.headerDateFormat = "MMM yy"
- Objective-c
_calendar.appearance.weekdayTextColor = [UIColor redColor];
_calendar.appearance.headerTitleColor = [UIColor redColor];
_calendar.appearance.eventColor = [UIColor greenColor];
_calendar.appearance.selectionColor = [UIColor blueColor];
_calendar.appearance.todayColor = [UIColor orangeColor];
_calendar.appearance.todaySelectionColor = [UIColor blackColor];
- Swift
calendar.appearance.weekdayTextColor = UIColor.redColor
calendar.appearance.headerTitleColor = UIColor.redColor
calendar.appearance.eventColor = UIColor.greenColor
calendar.appearance.selectionColor = UIColor.blueColor
calendar.appearance.todayColor = UIColor.orangeColor
calendar.appearance.todaySelectionColor = UIColor.blackColor
- Objective-C
calendar.appearance.borderRadius = 0
- Swift
calendar.appearance.borderRadius = 0
- Objective-C
// FSCalendarDataSource
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date
{
return yourSubtitle;
}
- Swift
// FSCalendarDataSource
func calendar(_ calendar: FSCalendar!, subtitleFor date: NSDate!) -> String! {
return yourSubtitle
}
- Objective-C
// FSCalendarDataSource
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date
{
return shouldShowEventDot;
}
- Swift
// FSCalendarDataSource
func calendar(calendar: FSCalendar!, hasEventForDate date: NSDate!) -> Bool {
return shouldShowEventDot
}
- Objective - c
// FSCalendarDataSource
- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date
{
return anyImage;
}
- Swift
// FSCalendarDataSource
func calendar(_ calendar: FSCalendar!, imageFor date: NSDate!) -> UIImage! {
return anyImage
}
- Objective-C
calendar.clipsToBounds = YES
- Swift
calendar.clipsToBounds = true
// FSCalendarDataSource
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
return yourMinimumDate;
}
- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
{
return yourMaximumDate;
}
- Objective - c
// FSCalendarDelegate
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
// Do something
}
- Swift
// FSCalendarDelegate
func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) {
}
- Objective - c
// FSCalendarDelegate
- (BOOL)calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date
{
if ([dateShouldNotBeSelected]) {
return NO;
}
return YES;
}
- Swift
func calendar(calendar: FSCalendar!, shouldSelectDate date: NSDate!) -> Bool {
if dateShouldNotBeSelected {
return false
}
return true
}
- Objective-C
- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar
{
// Do something
}
- Swift
func calendarCurrentMonthDidChange(_ calendar: FSCalendar!) {
// Do something
}
fakeSubtitles
andfakedSelectedDay
is only used for preview in Interface Builder
Just nill-out the today
property like:
self.calendar.today = nil;
self.calendar.appearance.headerMinimumDissolvedAlpha = 0.0;
Yes. Like UITableView or UICollectionView, there is also reloadData
in FSCalendar
;
[self.calendar reloadData];