Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/EvanCooper9/swift-week-view

An iOS calendar library for displaying calendar events in a week view.
https://github.com/EvanCooper9/swift-week-view

asynchronous calendar calendar-view ios swift swiftui week-view weekview

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        

# ECWeekView

See the [swiftui](https://github.com/EvanCooper9/swift-week-view/tree/swiftui) branch for updates.

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

## Installation
### Swift Package Manager
```
.package(url: "https://github.com/EvanCooper9/swift-week-view")
```

## Usage
### 1. Implement the `ECWeekViewDataSource`
Implement the `weekViewGenerateEvents` protocol function. This function should return a list of `ECWeekViewEvent`s 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](malcommac.github.io/SwiftDate/manipulate_dates.html#dateatunit) for SwiftDate documentation on creating date objects at specific times. Currently, events rely on a [24-hour clock](https://en.wikipedia.org/wiki/24-hour_clock).

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

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

return [event]
}
```
#### Available arguments for `ECWeekViewEvent`
- `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 `ECWeekView`, specify it's data source, and add it as a subview.

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

#### 2B. Storyboard
Add a view to the storyboard and set it's class `ECWeekView`. Assign the view's data source programmatically.
```Swift
@IBOutlet weak var weekView: ECWeekView!
weekView.dataSource = self
```

## User Interaction
To handle interaction with `ECWeekView`, implement the `ECWeekViewDelegate` protocol and set the `delegate` property to the implementing class.

```Swift
// Fires when a calendar event is touched on
func weekViewDidClickOnEvent(_ weekView: ECWeekView, event: ECWeekViewEvent, view: UIView)

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

## Custom Styling
To use custom styling, implement the `ECWeekViewStyler` protocol and assign the `styler` property to the implementing class. `ECWeekView` by default is its own styler.

```Swift
// Creates the view for an event
func weekViewStylerECEventView(_ weekView: ECWeekView, eventContainer: CGRect, event: ECWeekViewEvent) -> UIView

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