Skip to content

Latest commit

 

History

History
351 lines (249 loc) · 7.69 KB

MOREUSAGE.md

File metadata and controls

351 lines (249 loc) · 7.69 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

_calendar.allowsMultipleSelection = YES;

fscalendar-mulipleselection

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

_calendar.firstWeekday = 2; 

fscalendar---monday

The date format of header can be customized

_calendar.appearance.headerDateFormat = @"MMM yy";

fscalendar---headerformat

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];

fscalendar---colors

The day shape doesn't have to be a circle

  • Objective - c
_calendar.appearance.cellStyle = FSCalendarCellStyleRectangle;
  • Swift
calendar.appearance.cellStyle = .Rectangle

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!, subtitleForDate 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!, imageForDate 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

  • 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

Indian

calendar.identifier = NSCalendarIdentifierIndian;

indian

Persian

calendar.identifier = NSCalendarIdentifierPesian;

persian

Hebrew

calendar.identifier = NSCalendarIdentifierHebrew;

hebrew

Islamic

calendar.identifier = NSCalendarIdentifierIslamic;

islamic

Known issues

  • What if I don't need the today circle?
_calendar.today = nil;
_calendar.currentPage = [NSDate date];
  • Can we hide this? fscalendar---headeralpha
_calendar.appearance.headerMinimumDissolvedAlpha = 0.0;