### Setup calendarWeekView in viewDidLoad Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Call setupCalendar with number of days, date, events, scroll type, and first day of week. Use JZWeekViewHelper.getIntraEventsByDate to prepare events. ```swift calendarWeekView.setupCalendar(numOfDays: 7, setDate: Date(), allEvents: JZWeekViewHelper.getIntraEventsByDate(originalEvents: events), scrollType: .pageScroll, firstDayOfWeek: .Monday) ``` -------------------------------- ### Add JZCalendarWeekView pod to Podfile Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Add this line to your Podfile to install JZCalendarWeekView via CocoaPods. The comment recommends using the latest version before v1.0.0 release, optionally providing a version number. ```ruby # Latest release in CocoaPods (recommend to use latest version before v1.0.0 release, optional: provide version number) pod 'JZCalendarWeekView' ``` -------------------------------- ### Add JZCalendarWeekView to Cartfile Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Add this line to your Cartfile to install JZCalendarWeekView via Carthage. The comment recommends using the latest version before v1.0.0 release, optionally providing a version number. ```ruby # Latest release on Carthage (recommend to use latest version before v1.0.0 release, optional: provide version number) github "zjfjack/JZCalendarWeekView" ``` -------------------------------- ### Configure long press types and properties Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Set the delegate, data source, and long press types. Optionally adjust addNewDurationMins and moveTimeMinInterval. ```swift calendarWeekView.longPressDelegate = self calendarWeekView.longPressDataSource = self calendarWeekView.longPressTypes = [.addNew, .move] // Optional calendarWeekView.addNewDurationMins = 120 calendarWeekView.moveTimeMinInterval = 15 ``` -------------------------------- ### Update flow layout style Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Optionally customize the flow layout with hour height, row header width, column header height, and hour grid division. ```swift calendarWeekView.updateFlowLayout(JZWeekViewFlowLayout(hourHeight: 50, rowHeaderWidth: 50, columnHeaderHeight: 50, hourGridDivision: JZHourGridDivision.noneDiv)) ``` -------------------------------- ### Override viewWillTransition to support orientations Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Call JZWeekViewHelper.viewTransitionHandler in viewWillTransition to handle device orientation changes. ```swift override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { JZWeekViewHelper.viewTransitionHandler(to: size, weekView: calendarWeekView) } ``` -------------------------------- ### JZLongPressViewDelegate and DataSource protocols Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Implement these protocols to handle long press gestures. Delegate methods are called when add new or move long press ends or is cancelled. DataSource methods provide custom views for the long press. ```swift public protocol JZLongPressViewDelegate: class { /// When addNew long press gesture ends, this function will be called. func weekView(_ weekView: JZLongPressWeekView, didEndAddNewLongPressAt startDate: Date) /// When Move long press gesture ends, this function will be called. func weekView(_ weekView: JZLongPressWeekView, editingEvent: JZBaseEvent, didEndMoveLongPressAt startDate: Date) /// Sometimes the longPress will be cancelled because some curtain reason. func weekView(_ weekView: JZLongPressWeekView, longPressType: JZLongPressWeekView.LongPressType, didCancelLongPressAt startDate: Date) } public protocol JZLongPressViewDataSource: class { /// Implement this function to customise your own AddNew longPressView func weekView(_ weekView: JZLongPressWeekView, viewForAddNewLongPressAt startDate: Date) -> UIView /// Implement this function to customise your own Move longPressView func weekView(_ weekView: JZLongPressWeekView, movingCell: UICollectionViewCell, viewForMoveLongPressAt startDate: Date) -> UIView } ``` -------------------------------- ### Override viewForSupplementaryElementOfKind Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Override this function to provide your own supplementary views, including your current timeline. ```swift override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView ``` -------------------------------- ### Add JZCalendarWeekView dependency to Package.swift Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Add this Swift Package Manager dependency to your Package.swift file to include JZCalendarWeekView in your project. The version is set to up to next major from 0.7.2. ```swift .package(url: "https://github.com/zjfjack/JZCalendarWeekView.git", .upToNextMajor(from: "0.7.2")) ``` -------------------------------- ### All-Day Events Configuration Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Steps to enable the all-day events feature in JZCalendarWeekView. This involves inheriting from JZAllDayEvent and overriding viewForSupplementaryElementOfKind to update the all-day header. ```APIDOC ## All-Day Events Configuration ### Description Enables the display of all-day events in the calendar week view. Only events with isAllDay set to true are shown. ### Steps 1. Inherit your event class from `JZAllDayEvent` to add the `isAllDay` variable. 2. In your customised CalendarViewWeekView, override the `viewForSupplementaryElementOfKind` method and use `updateView` in `AllDayHeader` to update your all-day view with your own views. ### Notes - Events that cross multiple days should keep `isAllDay` false. ### Example Refer to the example project: `Example/JZCalendarWeekViewExample/Source/LongPressViews/LongPressWeekView.swift` ``` -------------------------------- ### Provide custom collection view cell Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Override cellForItemAt to dequeue and update your custom cell. Uses flowLayout.dateForColumnHeader and allEventsBySection. ```swift override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let date = flowLayout.dateForColumnHeader(at: indexPath) let cell = collectionView.dequeueReusableCell(withReuseIdentifier: EventCell.className, for: indexPath) as! EventCell cell.updateView(event: allEventsBySection[date]![indexPath.row] as! Event) return cell } ``` -------------------------------- ### Register custom view classes Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Override registerViewClasses to register your custom UICollectionReusableView subclasses. Must register decoration views with JZDecorationViewKinds and supplementary views with JZSupplementaryViewKinds. ```swift override func registerViewClasses() { super.registerViewClasses() // Register CollectionViewCell self.collectionView.register(UINib(nibName: "EventCell", bundle: nil), forCellWithReuseIdentifier: "EventCell") // Register DecorationView: must provide corresponding JZDecorationViewKinds self.flowLayout.register(BlackGridLine.self, forDecorationViewOfKind: JZDecorationViewKinds.verticalGridline) self.flowLayout.register(BlackGridLine.self, forDecorationViewOfKind: JZDecorationViewKinds.horizontalGridline) // Register SupplementrayView: must override collectionView viewForSupplementaryElementOfKind collectionView.register(RowHeader.self, forSupplementaryViewOfKind: JZSupplementaryViewKinds.rowHeader, withReuseIdentifier: "RowHeader") } ``` -------------------------------- ### Horizontal Scrollable Range Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Configuration of the horizontal scrollable range for the calendar week view. Allows setting a preferred scrollable range between startDate and endDate. ```APIDOC ## Horizontal Scrollable Range ### Description Sets the horizontal scrollable range for the CalendarWeekView. The view can only be scrolled horizontally between startDate (inclusive) and endDate (inclusive). Setting nil means no limit. ### Configuration - Set `scrollableRange` when calling `setupCalendar()` or by changing the variable directly. - If you change `scrollType` without calling `forceReload()`, you should call `setHorizontalEdgesOffsetX()` to reset the edges, because different scroll types have different edges. ### Notes - For further usage, check the example project, comments in code, or contact the author. ``` -------------------------------- ### getIntraEventsByDate Source: https://github.com/zjfjack/jzcalendarweekview/blob/master/README.md Static function in JZWeekViewHelper that transforms an array of JZBaseEvent subclasses into a dictionary keyed by date. This is used to prepare events for display in the calendar week view. ```APIDOC ## getIntraEventsByDate ### Description Transforms an array of events into a dictionary keyed by date, splitting events that cross midnight into separate entries. ### Method Static function ### Signature ```swift open class func getIntraEventsByDate(originalEvents: [T]) -> [Date: [T]] ``` ### Parameters - **originalEvents** ([T]) - Required - The array of events to transform. ### Return Value - [Date: [T]] - A dictionary mapping each date to an array of events occurring on that date. ### Usage Notes - The event class must be a subclass of JZBaseEvent and implement NSCopying. - Events that cross two days should be divided into two events with different intraStartDate and intraEndDate. ### Example ```swift let events = [MyEvent(...), MyEvent(...)] let eventsByDate = JZWeekViewHelper.getIntraEventsByDate(originalEvents: events) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.