Code Monkey home page Code Monkey logo

swift-week-view's Introduction

Swift-Week-View

An iOS calendar library for displaying calendar events in a week view.

Features

  • See calendar events in a week view
  • Asynchronously load calendar events
  • Interaction with specific events by clicking
  • Interaction with free time spaces by clicking
  • Custom styling
  • Infinite horizontal scrolling

What's New?

  • Using TimelineCollectionView as a foundation over a custom UIScrollView for improved stability
  • Improved display of events that overlap
  • Improved handling of asynchronously-fetched data
  • Bug fixes

Installation

Download Source files and install dependencies

Usage

1. Implement the WeekViewDataSource Protocol

Implement the weekViewGenerateEvents protocol function. This function should return a list of WeekViewEvents specific to the day of date. Events that can be created immediately should be returned to this function. Events that require time to create should be passed to eventCompletion, which will overwrite previously returned events. See here for SwiftDate documentation on creating date objects at specific times. Currently, events rely on a 24-hour clock.

func weekViewGenerateEvents(_ weekView: WeekView, date: DateInRegion, eventCompletion: @escaping ([WeekViewEvent]?) -> Void) -> [WeekViewEvent]? {
  let start: DateInRegion = date.dateBySet(hour: 12, min: 0, secs: 0)!
  let end: DateInRegion = date.dateBySet(hour: 13, min: 0, secs: 0)!
  let event: WeekViewEvent = WeekViewEvent(title: "Lunch", start: start, end: end)

  DispatchQueue.global(.background).async {
    // do some async work & create events...
    eventCompletion([event, ...])
  }

  return [event]
}

Available arguments for WeekViewEvent

  • title: the title of the event
  • subtitle: a subtitle or description of the event
  • start: the start time of the event
  • end: the end time of the event

2. Initialize the instance

2A. Programmatically

Create an instance of WeekView, specify it's data source, and add it as a subview.

let weekView = WeekView(frame: frame, visibleDays: 5)
weekView.dataSource = self
addSubview(weekView)
Available arguments for WeekView
  • frame: the frame of the calendar view
  • visibleDays: amount of days that are visible on one page. Default = 5
  • date: (Optional) the day WeekView will initially load. Default = today

2B. Storyboard

Add a view to the storyboard and set it's class WeekView. Assign the view's data source programmatically.

@IBOutlet weak var weekView: WeekView!
weekView.dataSource = self

User Interaction

To handle interaction with WeekView, implement the WeekViewDelegate protocol and set the delegate property to the implementing class.

// Fires when a calendar event is touched on
func weekViewDidClickOnEvent(_ weekView: WeekView, event: WeekViewEvent, view: UIView)

// Fires when a space without an event is tapped
func weekViewDidClickOnFreeTime(_ weekView: WeekView, date: DateInRegion)

Custom Styling

To use custom styling, implement the WeekViewStyler protocol and assign the styler property to the implementing class. WeekView by default is its own styler.

// Creates the view for an event
func weekViewStylerEventView(_ weekView: WeekView, eventContainer: CGRect, event: WeekViewEvent) -> UIView

// Create the header view for the day in the calendar. This would normally contain information about the date
func weekViewStylerHeaderView(_ weekView: WeekView, with date: DateInRegion, in cell: UICollectionViewCell) -> UIView

Dependencies

Included in Source as a framework. Make sure to add TimelineCollectionView.framework to your target's Embedded binaries.

Currently, SwiftDate versions 5.0.x are supported

pod 'SwiftDate', '~> 5.0'

Example

See the included example for basic implementation. Make sure to download the entire repository, and then open the .xcworkspace for it to work properly with the Source files and CocoaPods.

swift-week-view's People

Contributors

evancooper9 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.