Class
JTACMonthView
open class JTACMonthView: UICollectionView
Relationships
Conforms To
UICollectionView
UICollectionViewDataSource
UICollectionViewDelegate
UIScrollViewDelegate
Initializers
init()
public init()
Implemented by subclasses to initialize a new object (the receiver) immediately after memory for it has been allocated.
init(frame:collectionViewLayout:)
@available(*, unavailable, message: "Please use JTAppleCalendarMonthView() instead. It manages its own layout.")
public override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout)
Initializes and returns a newly allocated collection view object with the specified frame and layout.
Properties
selectedCells
open var selectedCells: (first: (date: Date, indexPath: IndexPath)?, last: (date: Date, indexPath: IndexPath)?)
Stores the first and last selected date cel
scrollDirection
open var scrollDirection: UICollectionView.ScrollDirection = .horizontal
The scroll direction of the sections in JTAppleCalendar.
cachedConfiguration
open var cachedConfiguration: ConfigurationParameters?
The configuration parameters setup by the developer in the confogureCalendar function
allowsDateCellStretching
open var allowsDateCellStretching = true
Enables/Disables the stretching of date cells. When enabled cells will stretch to fit the width of a month in case of a <= 5 row month.
isRangeSelectionUsed
@available(*, unavailable, renamed: "allowsRangedSelection")
open var isRangeSelectionUsed: Bool = false
Alerts the calendar that range selection will be checked. If you are not using rangeSelection and you enable this, then whenever you click on a datecell, you may notice a very fast refreshing of the date-cells both left and right of the cell you just selected.
allowsRangedSelection
open var allowsRangedSelection: Bool = false
rangeSelectionMode
open var rangeSelectionMode: RangeSelectionMode = .segmented
calendarDelegate
weak open var calendarDelegate: JTACMonthViewDelegate?
The object that acts as the delegate of the calendar view.
calendarDataSource
weak open var calendarDataSource: JTACMonthViewDataSource?
The object that acts as the data source of the calendar view.
sectionInset
open var sectionInset: UIEdgeInsets
minimumInteritemSpacing
open var minimumInteritemSpacing: CGFloat
minimumLineSpacing
open var minimumLineSpacing: CGFloat
scrollingMode
open var scrollingMode: ScrollingMode = .stopAtEachCalendarFrame
Configure the scrolling behavior
semanticContentAttribute
open override var semanticContentAttribute: UISemanticContentAttribute
A semantic description of the view’s contents, used to determine whether the view should be flipped when switching between left-to-right and right-to-left layouts.
ibCalendarDelegate
@IBOutlet public var ibCalendarDelegate: AnyObject?
Workaround for Xcode bug that prevents you from connecting the delegate in the storyboard. Remove this extra property once Xcode gets fixed.
ibCalendarDataSource
@IBOutlet public var ibCalendarDataSource: AnyObject?
Workaround for Xcode bug that prevents you from connecting the delegate in the storyboard. Remove this extra property once Xcode gets fixed.
delegate
@available(*, unavailable)
/// Will not be used by subclasses
open override var delegate: UICollectionViewDelegate?
dataSource
@available(*, unavailable)
/// Will not be used by subclasses
open override var dataSource: UICollectionViewDataSource?
Methods
collectionView(_:viewForSupplementaryElementOfKind:at:)
public func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView
Asks your data source object to provide a supplementary view to display in the collection view.
collectionView(_:willDisplay:forItemAt:)
public func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath)
collectionView(_:didHighlightItemAt:)
public func collectionView(_ collectionView: UICollectionView, didHighlightItemAt indexPath: IndexPath)
Tells the delegate that the item at the specified index path was highlighted.
collectionView(_:didUnhighlightItemAt:)
public func collectionView(_ collectionView: UICollectionView, didUnhighlightItemAt indexPath: IndexPath)
Tells the delegate that the item at the specified index path was unhighlighted.
collectionView(_:cellForItemAt:)
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
Asks your data source object for the cell that corresponds to the specified item in the collection view.
numberOfSections(in:)
public func numberOfSections(in collectionView: UICollectionView) -> Int
Asks your data sourceobject for the number of sections in the collection view. The number of sections in collectionView.
collectionView(_:numberOfItemsInSection:)
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
Asks your data source object for the number of items in the specified section. The number of rows in section.
collectionView(_:shouldSelectItemAt:)
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool
Asks the delegate if the specified item should be selected. true if the item should be selected or false if it should not.
collectionView(_:shouldDeselectItemAt:)
public func collectionView(_ collectionView: UICollectionView, shouldDeselectItemAt indexPath: IndexPath) -> Bool
Asks the delegate if the specified item should be deselected. true if the item should be deselected or false if it should not.
collectionView(_:didSelectItemAt:)
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
Tells the delegate that the item at the specified index path was selected. The collection view calls this method when the user successfully selects an item in the collection view. It does not call this method when you programmatically set the selection.
collectionView(_:didDeselectItemAt:)
public func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath)
Tells the delegate that the item at the specified path was deselected. The collection view calls this method when the user successfully deselects an item in the collection view. It does not call this method when you programmatically deselect items.
sizeOfDecorationView(indexPath:)
public func sizeOfDecorationView(indexPath: IndexPath) -> CGRect
cellStatusForDate(at:column:)
public func cellStatusForDate(at row: Int, column: Int) -> CellState?
Returns the cellStatus of a date that is visible on the screen. If the row and column for the date cannot be found, then nil is returned
-
Paramater row: Int row of the date to find
-
Paramater column: Int column of the date to find
Returns
- CellState: The state of the found cell
cellStatus(for:)
public func cellStatus(for date: Date) -> CellState?
Returns the cell status for a given date
Parameters
Name | Type | Description |
---|---|---|
Parameter | date Date of the cell you want to find |
Returns
- CellState: The state of the found cell
cellStatus(for:completionHandler:)
public func cellStatus(for date: Date, completionHandler: @escaping (_ cellStatus: CellState?) ->())
Returns the cell status for a given date
Parameters
Name | Type | Description |
---|---|---|
Parameter | date Date of the cell you want to find |
Returns
- CellState: The state of the found cell
monthStatus(for:)
public func monthStatus(for date: Date) -> Month?
Returns the month status for a given date
Parameters
Name | Type | Description |
---|---|---|
Parameter | date Date of the cell you want to find |
Returns
- Month: The state of the found month
cellStatus(at:)
public func cellStatus(at point: CGPoint) -> CellState?
Returns the cell status for a given point
Parameters
Name | Type | Description |
---|---|---|
Parameter | point of the cell you want to find |
Returns
- CellState: The state of the found cell
deselectAllDates(triggerSelectionDelegate:)
public func deselectAllDates(triggerSelectionDelegate: Bool = true)
Deselect all selected dates
Parameters
Name | Type | Description |
---|---|---|
Parameter | this funciton triggers a delegate call by default. Set this to false if you do not want this |
|
keepDeselectionIfMultiSelectionAllowed | if (in range selection) there are 4 dates. -> selected, unselected, selected, selected. (S | U | S | S) Deselecting those 4 dates again would give U | S | U | U. With KeepDeselection, this becomes U | U | U | U |
deselect(dates:triggerSelectionDelegate:keepDeselectionIfMultiSelectionAllowed:)
public func deselect(dates: [Date], triggerSelectionDelegate: Bool = true, keepDeselectionIfMultiSelectionAllowed: Bool = false)
Deselect dates
Parameters
Name | Type | Description |
---|---|---|
Parameter | Dates - The dates to deselect |
|
Parameter | triggerSelectionDelegate - this funciton triggers a delegate call by default. Set this to false if you do not want this |
|
keepDeselectionIfMultiSelectionAllowed | Bool |
if (in range selection) there are 4 dates. -> selected, unselected, selected, selected. (S | U | S | S) Deselecting those 4 dates again would give U | S | U | U. With KeepDeselection, this becomes U | U | U | U |
viewWillTransition(to:with:anchorDate:)
public func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator, anchorDate: Date?)
Notifies the container that the size of its view is about to change.
generateDateRange(from:to:)
public func generateDateRange(from startDate: Date, to endDate: Date) -> [Date]
Generates a range of dates from from a startDate to an endDate you provide Parameter startDate: Start date to generate dates from Parameter endDate: End date to generate dates to returns: - An array of the successfully generated dates
register(_:forSupplementaryViewOfKind:withReuseIdentifier:)
open override func register(_ viewClass: AnyClass?, forSupplementaryViewOfKind elementKind: String, withReuseIdentifier identifier: String)
Registers a class for use in creating supplementary views for the collection view. For now, the calendar only supports: 'UICollectionElementKindSectionHeader' for the forSupplementaryViewOfKind(parameter)
register(_:forSupplementaryViewOfKind:withReuseIdentifier:)
open override func register(_ nib: UINib?, forSupplementaryViewOfKind kind: String, withReuseIdentifier identifier: String)
Registers a class for use in creating supplementary views for the collection view. For now, the calendar only supports: 'UICollectionElementKindSectionHeader' for the forSupplementaryViewOfKind(parameter)
dequeueReusableJTAppleSupplementaryView(withReuseIdentifier:for:)
public func dequeueReusableJTAppleSupplementaryView(withReuseIdentifier identifier: String, for indexPath: IndexPath) -> JTACMonthReusableView
Dequeues re-usable calendar cells
registerDecorationView(nib:)
public func registerDecorationView(nib: UINib?)
Registers a nib for use in creating Decoration views for the collection view.
register(viewClass:forDecorationViewOfKind:)
public func register(viewClass className: AnyClass?, forDecorationViewOfKind kind: String)
Registers a class for use in creating Decoration views for the collection view.
dequeueReusableJTAppleCell(withReuseIdentifier:for:)
public func dequeueReusableJTAppleCell(withReuseIdentifier identifier: String, for indexPath: IndexPath) -> JTACDayCell
Dequeues a reuable calendar cell
reloadData(withAnchor:completionHandler:)
public func reloadData(withAnchor date: Date? = nil, completionHandler: (() -> Void)? = nil)
Reloads the data on the calendar view. Scroll delegates are not
Parameters
Name | Type | Description |
---|---|---|
date | Date? |
An anchordate that the calendar will scroll to after reload completes |
animation | Scroll is animated if this is set to true |
|
completionHandler | (() -> Void)? |
This closure will run after the reload is complete |
reloadDates(_:)
public func reloadDates(_ dates: [Date])
Reload the date of specified date-cells on the calendar-view
Parameters
Name | Type | Description |
---|---|---|
dates | [Date] |
Date-cells with these specified dates will be reloaded |
selectDates(from:to:triggerSelectionDelegate:keepSelectionIfMultiSelectionAllowed:)
public func selectDates(from startDate: Date, to endDate: Date, triggerSelectionDelegate: Bool = true, keepSelectionIfMultiSelectionAllowed: Bool = false)
Select a date-cell range
Parameters
Name | Type | Description |
---|---|---|
startDate | Date |
Date to start the selection from |
endDate | Date |
Date to end the selection from |
triggerDidSelectDelegate | Triggers the delegate function only if the value is set to true. Sometimes it is necessary to setup some dates without triggereing the delegate e.g. For instance, when youre initally setting up data in your viewDidLoad |
|
keepSelectionIfMultiSelectionAllowed | Bool |
This is only applicable in allowedMultiSelection = true. This overrides the default toggle behavior of selection. If true, selected cells will remain selected. |
deselectDates(from:to:triggerSelectionDelegate:keepDeselectionIfMultiSelectionAllowed:)
public func deselectDates(from start: Date, to end: Date? = nil, triggerSelectionDelegate: Bool = true, keepDeselectionIfMultiSelectionAllowed: Bool = false)
Deselect all selected dates within a range
Parameters
Name | Type | Description |
---|---|---|
Parameter | start - Start of date range to deselect |
|
Parameter | end of date range to deselect |
|
keepDeselectionIfMultiSelectionAllowed | Bool |
if (in range selection) there are 4 dates. -> selected, unselected, selected, selected. (S | U | S | S) Deselecting those 4 dates again would give U | S | U | U. With KeepDeselection, this becomes U | U | U | U |
selectDates(_:triggerSelectionDelegate:keepSelectionIfMultiSelectionAllowed:)
public func selectDates(_ dates: [Date], triggerSelectionDelegate: Bool = true, keepSelectionIfMultiSelectionAllowed: Bool = false)
Select a date-cells
Parameters
Name | Type | Description |
---|---|---|
date | The date-cell with this date will be selected |
|
triggerDidSelectDelegate | Triggers the delegate function only if the value is set to true. Sometimes it is necessary to setup some dates without triggereing the delegate e.g. For instance, when youre initally setting up data in your viewDidLoad |
|
keepSelectionIfMultiSelectionAllowed | Bool |
if (in range selection) there are 4 dates. -> selected, unselected, selected, selected. (S | U | S | S) Selecting those 4 dates again would give U | S | U | U. With KeepSelection, this becomes S | S | S | S |
scrollToSegment(_:triggerScrollToDateDelegate:animateScroll:extraAddedOffset:completionHandler:)
public func scrollToSegment(_ destination: SegmentDestination,
triggerScrollToDateDelegate: Bool = true,
animateScroll: Bool = true,
extraAddedOffset: CGFloat = 0,
completionHandler: (() -> Void)? = nil)
Scrolls the calendar view to the next section view. It will execute a completion handler at the end of scroll animation if provided.
-
Paramater direction: Indicates a direction to scroll
-
Paramater animateScroll: Bool indicating if animation should be enabled
Parameters
Name | Type | Description |
---|---|---|
triggerScrollToDateDelegate | Bool |
trigger delegate if set to true |
completionHandler | (() -> Void)? |
A completion handler that will be executed at the end of the scroll animation |
scrollToDate(_:triggerScrollToDateDelegate:animateScroll:preferredScrollPosition:extraAddedOffset:completionHandler:)
public func scrollToDate(_ date: Date,
triggerScrollToDateDelegate: Bool = true,
animateScroll: Bool = true,
preferredScrollPosition: UICollectionView.ScrollPosition? = nil,
extraAddedOffset: CGFloat = 0,
completionHandler: (() -> Void)? = nil)
Scrolls the calendar view to the start of a section view containing a specified date.
-
Paramater date: The calendar view will scroll to a date-cell containing this date if it exists
-
Paramater animateScroll: Bool indicating if animation should be enabled
-
Paramater preferredScrollPositionIndex: Integer indicating the end scroll position on the screen. This value indicates column number for Horizontal scrolling and row number for a vertical scrolling calendar
Parameters
Name | Type | Description |
---|---|---|
triggerScrollToDateDelegate | Bool |
Trigger delegate if set to true |
completionHandler | (() -> Void)? |
A completion handler that will be executed at the end of the scroll animation |
scrollToHeaderForDate(_:triggerScrollToDateDelegate:withAnimation:extraAddedOffset:completionHandler:)
public func scrollToHeaderForDate(_ date: Date,
triggerScrollToDateDelegate: Bool = false,
withAnimation animation: Bool = false,
extraAddedOffset: CGFloat = 0,
completionHandler: (() -> Void)? = nil)
Scrolls the calendar view to the start of a section view header. If the calendar has no headers registered, then this function does nothing
-
Paramater date: The calendar view will scroll to the header of a this provided date
visibleDates()
public func visibleDates()-> DateSegmentInfo
Returns the visible dates of the calendar.
Returns
- DateSegmentInfo
visibleDates(_:)
public func visibleDates(_ completionHandler: @escaping (_ dateSegmentInfo: DateSegmentInfo) ->())
Returns the visible dates of the calendar.
Returns
- DateSegmentInfo
reloadData()
@available(*, unavailable)
open override func reloadData()
scrollViewDidScrollToTop(_:)
public func scrollViewDidScrollToTop(_ scrollView: UIScrollView)
Inform the scrollViewDidEndDecelerating function that scrolling just occurred
scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)
open func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>)
Tells the delegate when the user finishes scrolling the content.
scrollViewDidEndDragging(_:willDecelerate:)
public func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool)
scrollViewDidEndScrollingAnimation(_:)
public func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView)
Tells the delegate when a scrolling animation in the scroll view concludes.
scrollViewDidEndDecelerating(_:)
open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)
Tells the delegate that the scroll view has ended decelerating the scrolling movement.
scrollViewDidScroll(_:)
public func scrollViewDidScroll(_ scrollView: UIScrollView)
Tells the delegate that a scroll occurred