Quick Start Guide


This is a brief introduction to using the ShinobiCalendars component. This quick start guide walks you through a series of simple steps to create the following calendar:

Result of the quick start tutorial

Creating a Simple Calendar

Start up Xcode and create a new project via File / New / Single View Application.

Within your newly created project, add a reference to the ShinobiCalendars framework. The easiest way to do this is to add it to your project by locating the ShinobiCalendars.framework and dragging it directly into your project.

Adding a Calendar

You can follow along with GettingStarted.xcodeproj in the Samples/ folder of your framework download. The first step is to create an instance of the calendar and add it to the view. Open up the ViewController.m file and add the following import statement.

#import <ShinobiCalendars/ShinobiCalendars.h>

Then add property for the calendar.

@interface ViewController ()

@property (strong, nonatomic) ShinobiCalendar *calendar;


In the viewDidLoad method, add the following code:

self.calendar = [[ShinobiCalendar alloc] initWithFrame:self.view.bounds];
self.calendar.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
self.calendar.dataSource = self;
[self.calendar registerEventViewClass:[SCalendarEventView class] forEventReuseIdentifier:@"eventView"];
[self.view addSubview:self.calendar];

When setting the dataSource of the calendar, you must ensure that the value conforms to the SCalendarDataSource property. In this case, the value is self, so change the interface so it looks like this:

@interface ViewController () SCalendarDataSource

To provide the calendar with events, implement the following method:

- (NSArray *)shinobiCalendar:(ShinobiCalendar *)calendar eventsForDate:(NSDate *)date;

Using the following as the implementation for this method will display an event on every date at 12:00 to 16:00. You can return as many events as you like from this method - the calendar will handle how they are displayed for you.

SCalendarEvent *event = [SCalendarEvent new];
event.startTime = [date dateByAddingTimeInterval:60 * 60 * 12];
event.endTime = [date dateByAddingTimeInterval:60 * 60 * 16];
event.name = @"event";
return @[event];

You must also provide a view that is capable of displaying individual events. Notice how in the viewDidLoad method, an event view class is registered for a certain identifier. That allows the calendar to reuse the event views, in a similar way to how a UITableView reuses UITableViewCells. This is discussed in depth in the control overview below, but for now, let’s keep it simple. Implement the following method, which will return an SCalendarEventView instance.

- (SCalendarEventView *)shinobiCalendar:(ShinobiCalendar *)calendar eventViewForEvent:(SCalendarEvent *)event {
    return [calendar dequeueReusableEventViewWithIdentifier:@"eventView"];

That’s all there is to it! You should now have a Calendar in your application. For further information on the calendar’s features, see the user guide.