Skip to content
BB9z edited this page Jun 8, 2021 · 2 revisions

Advanced API

For some additional funcionality there are a few handy techniques which can be useful for your app.

Starter Weekday

You might want to use a specific first weekday in CVCalendar. And it's possible to set any weekday as the first one.

NOTE: Initilially, CVCalendar's figuring out your system calendar's first weekday and sets it as its own.

Simply implement a method named func firstWeekday() -> Weekday form CVCalendarViewDelegate. Then set the appropriate enum value. Look at Weekday enum values.

func firstWeekday() -> Weekday {
    return .Sunday
}
Toggling.

It's possible to toggle from any month view to any month view by calling a special method in CVCalendarView and passing any date of this MonthView you wish to present in the calendar. For example, let's make a @IBAction method that is connected with Today button and toggles to the present month.

@IBAction func todayMonthView() {
    self.calendarView.toggleCurrentDayView()
}

As well you're able to toggle to any month. Let's create a method that changes MonthView with the given offset of current month.

func toggleMonthViewWithMonthOffset(offset: Int) {
    let calendar = NSCalendar.currentCalendar()
    let calendarManager = CVCalendarManager.sharedManager
    let components = calendarManager.componentsForDate(NSDate()) // from today

    components.month += offset
    components.day = 1 // CVCalendar will select this day view

    let resultDate = calendar.dateFromComponents(components)!

    self.calendarView.toggleMonthViewWithDate(resultDate)
}
Switching.

Also you can simply switch between next and previous MonthViews relatively to the presented one. Let's say the presented MonthView is January then the previous one is December and the next one is February if you have special buttons ("<" - to the previous, ">" - to the next) the following methods will help you easily switch between MonthViews.

For loading next MonthView.

self.calendarView.loadNextMonthView()

For loading previous MonthView.

self.calendarView.loadPreviousMonthView()
Days out hiding.

It's possible not to show days out of the presented month. First, CVCalendar provides a special method for (un)hiding days out with animation. Second, once you've made days out hidden ones it doesn't mean CVCalendar won't show them anymore. You also have to pass an appropriate value in shouldShowWeekdaysOut: method to notify CVCalendar you don't want to show days out.

For animatable hiding.

self.calendarView!.changeDaysOutShowingState(true) // just hide days out in loaded Month Views
self.shouldShowDaysOut = false // passing value for 'shouldShowWeekdaysOut:'

Unhiding.

self.calendarView!.changeDaysOutShowingState(false) // just unhide days out in loaded Month Views
self.shouldShowDaysOut = true // passing value for 'shouldShowWeekdaysOut:'
Changing the presentation mode.

If you want to animate the calendar from one presentation mode to another then simply call func changeMode(mode: CalendarMode) method from CVCalendarView instance passing an appropriate value.

/// Switch to WeekView mode.
@IBAction func toWeekView(sender: AnyObject) {
    calendarView.changeMode(.WeekView)
}

/// Switch to MonthView mode.
@IBAction func toMonthView(sender: AnyObject) {
    calendarView.changeMode(.MonthView)
}