Skip to content

Latest commit

 

History

History
372 lines (259 loc) · 7.71 KB

MOREUSAGE.md

File metadata and controls

372 lines (259 loc) · 7.71 KB

More usage

If you want FSCalendar to scroll vertically

  • Objective - c
_calendar.scrollDirection = FSCalendarScrollDirectionVertical;
  • Swift
calendar.scrollDirection = .vertical 

fscalendar-vertical

If you want FSCalendar to scroll horizontally (Default)

  • Objective - c
_calendar.scrollDirection = FSCalendarScrollDirectionHorizontal; // By default
  • Swift
calendar.scrollDirection = .Horizontal 

fscalendar-horizontal

Focus on selected date on week mode

fscalendar-scope

  • There are cases such as Changing ScopeChanging 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};
}

For week mode

  • Objective-C
_calendar.scope = FSCalendarScopeWeek;
  • Swift
calendar.scope = .week 

For month mode

  • Objective - c
_calendar.scope = FSCalendarScopeMonth; // By default
  • Swift
calendar.scope = .month 

fscalendar-scope

To select more than one date

  • Objective-C
calendar.allowsMultipleSelection = YES;
  • Swift
calendar.allowsMultipleSelection = true;

fscalendar-mulipleselection

If you want FSCalendar to use Monday as the first column (or any other weekday)

  • Objective-C
_calendar.firstWeekday = 2; 
  • Swift
calendar.firstWeekday = 2

fscalendar---monday

The date format of header can be customized

  • Objective-C
calendar.appearance.headerDateFormat = @"MMM yy";
  • Swift
calendar.appearance.headerDateFormat = "MMM yy"

fscalendar---headerformat

You can define the appearance

  • 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

fscalendar---colors

The day shape doesn't have to be a circle

  • Objective-C
calendar.appearance.borderRadius = 0
  • Swift
calendar.appearance.borderRadius = 0

fscalendar---rectangle

FSCalendar can show subtitle for each day

  • Objective-C
// FSCalendarDataSource
- (NSString *)calendar:(FSCalendar *)calendar subtitleForDate:(NSDate *)date
{
    return yourSubtitle;
}
  • Swift
// FSCalendarDataSource
func calendar(_ calendar: FSCalendar!, subtitleFor date: NSDate!) -> String! {
    return yourSubtitle
}

fscalendar---subtitle2
fscalendar---subtitle1

And event dot for some days

  • Objective-C
// FSCalendarDataSource
- (BOOL)calendar:(FSCalendar *)calendar hasEventForDate:(NSDate *)date
{
    return shouldShowEventDot;
}
  • Swift
// FSCalendarDataSource
func calendar(calendar: FSCalendar!, hasEventForDate date: NSDate!) -> Bool {
    return shouldShowEventDot
}

Or image for some days

  • Objective - c
// FSCalendarDataSource
- (UIImage *)calendar:(FSCalendar *)calendar imageForDate:(NSDate *)date
{
    return anyImage;
}
  • Swift
// FSCalendarDataSource
func calendar(_ calendar: FSCalendar!, imageFor date: NSDate!) -> UIImage! {
    return anyImage
}

fscalendar---image

You can hide top and bottom borders

  • Objective-C
calendar.clipsToBounds = YES
  • Swift
calendar.clipsToBounds = true

fscalendar---image

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

  • Objective - c
// FSCalendarDelegate
- (void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date
{
    // Do something
}
  • Swift
// FSCalendarDelegate
func calendar(calendar: FSCalendar!, didSelectDate date: NSDate!) {
    
}

You can prevent it from being selected

  • 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
}

You will get notified when FSCalendar changes the month or week

  • Objective-C
- (void)calendarCurrentMonthDidChange:(FSCalendar *)calendar
{
    // Do something
}
  • Swift
func calendarCurrentMonthDidChange(_ calendar: FSCalendar!) {
    // Do something
}
  • fakeSubtitles and fakedSelectedDay is only used for preview in Interface Builder

Q & A

Q:  What if I don't need the today circle?

Just nill-out the today property like:

self.calendar.today = nil;

Q:  Can we hide this?

fscalendar---headeralpha

self.calendar.appearance.headerMinimumDissolvedAlpha = 0.0;

Q:  Can we refresh the calendar after a network request?

Yes. Like UITableView or UICollectionView, there is also reloadData in FSCalendar;

[self.calendar reloadData];