If you want FSCalendar
to scroll vertically
_calendar.scrollDirection = FSCalendarScrollDirectionVertical;
calendar. scrollDirection = . Vertical
If you want FSCalendar
to scroll horizontally (Default)
_calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default
calendar. scrollDirection = . Horizontal
Focus on selected date on week mode
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 };
}
_calendar.scope = FSCalendarScopeWeek;
_calendar.scope = FSCalendarScopeMonth; // By default
To select more than one date
_calendar.allowsMultipleSelection = YES ;
If you want FSCalendar
to use Monday
as the first column (or any other weekday)
_calendar.firstWeekday = 2 ;
The date format of header can be customized
_calendar.appearance.headerDateFormat = @" MMM yy" ;
You can define the appearance
_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 ];
The day shape doesn't have to be a circle
_calendar.appearance.cellStyle = FSCalendarCellStyleRectangle;
calendar. appearance. cellStyle = . Rectangle
FSCalendar
can show subtitle for each day
// FSCalendarDataSource
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date
{
return yourSubtitle;
}
// FSCalendarDataSource
func calendar( calendar: FSCalendar ! , subtitleForDate date: NSDate ! ) -> String ! {
return yourSubtitle
}
And event dot for some days
// FSCalendarDataSource
- (BOOL )calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date
{
return shouldShowEventDot;
}
// FSCalendarDataSource
func calendar( calendar: FSCalendar ! , hasEventForDate date: NSDate ! ) -> Bool {
return shouldShowEventDot
}
// FSCalendarDataSource
- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date
{
return anyImage;
}
// FSCalendarDataSource
func calendar( calendar: FSCalendar ! , imageForDate date: NSDate ! ) -> UIImage ! {
return anyImage
}
You can hide top and bottom borders
calendar.clipsToBounds = YES
calendar. clipsToBounds = true
There are left and right boundaries
// FSCalendarDataSource
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
return yourMinimumDate;
}
- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
{
return yourMaximumDate;
}
You can do something when a date is selected
// FSCalendarDelegate
- (void )calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
// Do something
}
// FSCalendarDelegate
func calendar( calendar: FSCalendar ! , didSelectDate date: NSDate ! ) {
}
You can prevent it from being selected
// FSCalendarDelegate
- (BOOL )calendar:(FSCalendar *)calendar shouldSelectDate:(NSDate *)date
{
if ([dateShouldNotBeSelected]) {
return NO ;
}
return YES ;
}
func calendar( calendar: FSCalendar ! , shouldSelectDate date: NSDate ! ) -> Bool {
if dateShouldNotBeSelected {
return false
}
return true
}
You will get notified when FSCalendar
changes the month
- (void )calendarCurrentMonthDidChange:(FSCalendar *)calendar
{
// Do something
}
func calendarCurrentMonthDidChange( calendar: FSCalendar ! ) {
// Do something
}
fakeSubtitles
and fakedSelectedDay
is only used for preview in Interface Builder
calendar.identifier = NSCalendarIdentifierIndian ;
calendar.identifier = NSCalendarIdentifierPesian;
calendar.identifier = NSCalendarIdentifierHebrew ;
calendar.identifier = NSCalendarIdentifierIslamic ;
What if I don't need the today
circle?
_calendar.today = nil ;
_calendar.currentPage = [NSDate date ];
Can we hide this?
_calendar.appearance.headerMinimumDissolvedAlpha = 0.0 ;