Skip to content

Repository files navigation

QVRWeekView

VersionLicensePlatform

About

QVRWeekView is a work in progress framework that contains a week/day view that allows you to display, add and remove events.

Features

  • Horizontal and vertical scrolling
  • Infinite horizontal scrolling
  • Zooming
  • Colour, size and font customization features
  • Day and hour label font resizing
  • Dynamic event adding and removing
  • Event tap, long press and event request callbacks
  • Number of visible days customizable

Example

To run the example project, clone the repo, and run pod install from the Example directory first. Most useful example code can be found in Example > QVRWeekView > CalendarViewController or StartViewController

Requirements

This pod requires a minimum deployment target of iOS 9.0.

Installation

QVRWeekView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod"QVRWeekView"

Usage

Setup

Once the framework is installed, there are two ways you can incorporate the WeekView into your project:

1. Programatically

To add the WeekView programatically, simply import QVRWeekView into your code by adding:

importQVRWeekView

at the top of your source file containing your view controller. Then insert the WeekView into your view controller by adding:

letweekView=WeekView(frame: self.view.frame)self.view.addSubview(weekView)

into either your viewDidLoad or viewWillAppear method.

2. Via the storyboard

To add the WeekView via the storyboard, simply add a View onto your View Controller and resize it or add constraints. Then go to the identity inspector of your view and select the Class to be WeekView and the module to be QVRWeekView (See image).

image

Then you should be all set!

Working with WeekView

WeekView Delegate

WeekView has a delegate called WeekViewDelegate. For now this delegate contains only three functions:

FunctionParametersBehaviourRecommended use
didLongPressDayViewweekView:WeekView, date:DateCalled when a dayView column is long pressed. The passed date contains which time point was pressedUse this to trigger the creation of an event
didTapEventweekView:WeekView, eventId:IntCalled when an event is tapped. eventId of the tapped event is passedUse this to prompt event editing or removal
eventLoadRequestweekView:WeekView, startDate:Date , endDate:DateCalled when events are ready to be loaded. startDate and endDate indicate (inclusively) between which two dates events are required.Use this to load in stored events
activeDayChangedweekView:WeekView, date: DateCalled when the current leftmost day changes.Use this to keep track of current active day
didEndZoomingweekView:WeekView, scale: DoubleCalled when zooming stops, the scale is the current zoomScaleUse this to persist the zoom scale of the WeekView
didEndVerticalScrollingweekView:WeekView, top: Double, bottom: DoubleCalled when vertical scrolling stops. The top an bottom values are percentages values of how far down the screen is.Use this to persist vertical position of the WeekView

WeekView Public Functions

FunctionParametersBehaviour
updateTimeDisplayed\Updates the time displayed by the hour indicator
showDaydate:DateScrolls the week view to the day passed by date
showToday\Scrolls the week view to today
loadEventseventsData:[EventData]Loads, processes and displays the events provided by the eventsData array of EventData1 objects. Passing an empty array removes all visible events.
redrawEventsTriggers a setNeedsLayout on all DayViewCells and will trigger a redrawing of all events

WeekView Public Properties

PropertyTypeDescription
allVisibleEvents[EventData]An array of EventData of the events currently visible on screen
visibleDayDateRangeClosedRange<DayDate>A ClosedRange of DayDates of the day columns which are currently visible on screen
delegateWeekViewDelegate?The delegate of this WeekView

EventData1

EventData is the main object used to communicate events between the WeekView and your code. EventData can be overriden.

Variable/FunctionPurpose
id:StringA unique identifier for this event
title:StringA title that will be displayed for this event
locating:StringThe "location" of this event (or any other data you wish to be displayed alongside the title in an event)
startDate:DateThe start date for this event
endDate:DateThe end date for this event
color:UIColorThe main color for this event
allDay:BoolIndicates if this event is an all day event, all day events are displayed along the top bar
configureGradient(CAGradientLayer?) -> VoidUse to configure a gradient that will be used to render your event instead of just a solid color

Saving and Persisting Events

Events can be stored in Core Data (the following guide assumes some basic knowledge of Core Data):

  1. Create a new Core Data model if you don't have one already. Create a new Entity in this model.
  2. Add a new Attribute of type Transformable to the new Entity.
  3. Select the new Attribute and make sure its CustomClass is set to (this can be changed in the right-hand side menu):
    • EventDataArray if you want to store an array of events
    • EventData if you want to store a single event
  4. If you are getting Undeclared Type warnings, you may need to add @import QVRWeekView to your [ProjectName]-Bridging-Header.h file.
  5. You can now use the new Core Data Entity to persist EventData objects.

The EventDataArray class has a single variable: eventsData: [EventData] and is simply used as a proxy to store an array of events.

A detailed example can be found in the example Project folder /Example. A more detailed guide can be found here.

Customizing WeekView

Below is a table of all customizable properties of the WeekView

PropertyDescriptionDefault
mainBackgroundColor:UIColorThe background color of the WeekView.dark grey: #cacaca
defaultTopBarHeight:CGFloatThe default height of the top bar containing the day labels.35
topBarColor:UIColorThe color of the top bar containing the day labels.grey: #dcdcdc
sideBarWidth:CGFloatThe width of the sidebar containing the hour labels.25
sideBarColor:UIColorThe color of the sidebar containing the hour labels.dark grey: #cacaca
dayLabelDefaultFont:UIFontThe default font the the day labels.boldSystemFont size: 14
dayLabelTextColor:UIColorThe text color of the day labels.black: #000
dayLabelTodayTextColor:UIColorThe text color of the today day label.dark blue: #14426f
dayLabelMinimumFontSize:CGFloatThe minimum day label font size. Used during automatic resizing.8
dayLabelShortDateFormat:StringThe date format of the day label when there is not enough space to display the normal date format. Date formats can be found here.d MMM
dayLabelNormalDateFormat:StringThe date format of the day label when there is not enough space to display the long date format. Date formats can be found here.E d MMM
dayLabelLongDateFormat:StringThe longest date format of the day label, only shown when there is enough space to display it. Date formats can be found here.E d MMM y
dayLabelDateLocale:LocaleLocale used by the day label formatter. Locales can be found hereNSLocale.current
hourLabelFont:UIFontThe font the the hour labels.boldSystemFont size: 12
hourLabelTextColor:UIColorThe text color of the hour labels.black #000
hourLabelMinimumFontSize:CGFloatThe minimum day label font size. Used during automatic resizing.6
hourLabelDateFormat:StringThe date format used to display the hours in the side bar.HH
allDayEventHeight:CGFloatThe height of an all day event.40
allDayEventVerticalSpacing:CGFloatThe vertical spacing above and below an all day event.5
allDayEventsSpreadOnX:BoolWhen enabled, all day events are displayed next to each other, instead of above and below each other.true
autoConvertAllDayEvents:BoolWhen enabled, events that cross multiple days will be converted to all day events.true
visibleDaysInPortraitMode:IntThe amount of day columns visible in portrait mode.2
visibleDaysInLandscapeMode:IntThe amount day columns visible in landscape mode.7
eventLabelFont:UIFontThe font of the text inside events.boldSystemFont size: 12
eventLabelInfoFont:UIFontThe info font of the text inside events.boldFont size: 12
eventLabelTextColor:UIColorThe color of the text inside events.white #fff
eventLabelHorizontalTextPadding:CGFloatHorizontal padding of the text within event labels.2
eventLabelVerticalTextPadding:CGFloatVertical padding of the text within event labels.2
eventStyleCallback:(CALayer, EventData?) -> VoidUse this callback to customise an Event layer any way you want. The EventData will be nil if it is the Preview Event layer that is being rendered. Example usage in CalendarViewController.nil
previewEventText:StringThe text shown inside the preview event.New Event
previewEventColor:UIColorThe color of the preview event.random color
previewEventHeightInHours:DoubleHeight of the preview event in hours.2.0
previewEventPrecisionInMinutes:DoubleThe number of minutes the preview event will snap to. Ex: 15.0 will snap preview event to nearest 15 minutes.15.0
showPreviewOnLongPress:BoolWhen enabled a preview event will be displayed on a long press.true
defaultDayViewColor:UIColorThe default color of a day column.light grey #f8f8f8
weekendDayViewColor:UIColorThe color of a weekend day column.grey #eaeaea
passedDayViewColor:UIColorThe color of a day column that is in the past.grey #f0f0f0
passedWeekendDayViewColor:UIColorThe color of a weekend day column that is in the past.grey #e4e4e4
todayViewColor:UIColorThe color of today's day column.light grey #f8f8f8
showTodayTimeOverlay:BoolShow or hide "current time" overlay in the today day view cell.true
dayViewCellInitialHeight:CGFloatHeight for the day columns. This is the initial height for zoom scale = 1.0.1400
dayViewHourIndicatorColor:UIColorColor of the current hour indicator.very dark grey #5a5a5a
dayViewHourIndicatorThickness:CGFloatThickness (or height) of the current hour indicator.3
dayViewMainSeparatorColor:UIColorColor of the main hour separators in the day view cells. Main separators are full lines and not dashed.dark grey: #cacaca
dayViewMainSeparatorThickness:CGFloatThickness of the main hour separators in the day view cells. Main separators are full lines and not dashed.1
dayViewDashedSeparatorColor:UIColorColor of the dashed/dotted hour separators in the day view cells.dark grey: #cacaca
dayViewDashedSeparatorThickness:CGFloatThickness of the dashed/dotted hour separators in the day view cells.1
dayViewDashedSeparatorPattern:[NSNumber]Sets the pattern for the dashed/dotted hour separators. Requires an array of NSNumbers. Example 1: (10, 5) will set a pattern of 10 points drawn, 5 points empty, repeated. Example 2: (3, 4, 9, 2) will set a pattern of 4 points drawn, 4 points empty, 9 points drawn, 2 points empty, repeated. See Apple API for additional information on pattern drawing.[3, 1]
portraitDayViewSideSpacing:CGFloatAmount of spacing in between day columns when in portrait mode.5
landscapeDayViewSideSpacing:CGFloatAmount of spacing in between day columns when in landscape mode.1
portraitDayViewVerticalSpacing:CGFloatAmount of spacing above and below day columns when in portrait mode.15
landscapeDayViewVerticalSpacing:CGFloatAmount of spacing above and below day columns when in landscape mode.10
minimumZoomScale:CGFloatThe minimum zoom scale to which the weekview can be zoomed. Ex. 0.5 means that the weekview can be zoomed to half the original given dayViewCellHeight.0.75
currentZoomScale:CGFloatThe current zoom scale to which the weekview will be zoomed. Ex. 0.5 means that the weekview will be zoomed to half the original given dayViewCellHeight.1.0
maximumZoomScale:CGFloatThe maximum zoom scale to which the weekview can be zoomed. Ex. 2.0 means that the weekview can be zoomed to double the original given dayViewCellHeight.3.0
velocityOffsetMultiplier:CGFloatSensitivity for horizontal scrolling. A higher number will multiply input velocity more and thus result in more cells being skipped when scrolling.0.75
horizontalScrolling:HorizontalScrollingUsed to determine horizontal scrolling behaviour. .infinite is infinite scrolling, .finite(number, startDate) is finite scrolling for a given number of days from the starting date..infinite

How it works

The main WeekView view is a subclass of UIView. The view layout is retrieved from the WeekView xib file. WeekView contains a top and side bar sub view. The side bar contains an HourSideBarView which displays the hours. WeekView also contains a DayScrollView (UIScrollView subclass) which controls vertical scrolling and also delegates and contains a DayCollectionView (UICollectionView subclass) which controls the horizontal scrolling. DayCollectionView cells are DayViewCells, whose view is generated programtically (due to inefficiencies caused by auto-layout).

WeekView handles all top level operations such as pinch gestures and orientation change. Scrolling of the top and side bar is handled by a function inside of WeekView which is called by the DayScrollView when scrolling. Top bar day labels are generated, displayed and discarded simulaneously with DayCollectionView cells by the WeekView.

Upcoming features

  • Ability to add and remove events
  • Event color customization
  • Extra customization features
  • Improved UI features
  • Increased event processing efficiency
  • Add scroll to all day events

Author

Reinert Lemmens, reilemx@gmail.com

License

QVRWeekView is available under the MIT license. See the LICENSE file for more info.

About

QVRWeekView is a framework which provides a calendar view that can be customized to display between 1 to 7 days in both portrait and landscape mode. Includes customization features to customize colours, fonts and sizes.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages