-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathMGCMonthPlannerView.h
More file actions
executable file
·556 lines (448 loc) · 21.5 KB
/
MGCMonthPlannerView.h
File metadata and controls
executable file
·556 lines (448 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
//
// MGCMonthPlannerView.h
// Graphical Calendars Library for iOS
//
// Distributed under the MIT License
// Get the latest version from here:
//
// https://github.com/jumartin/Calendar
//
// Copyright (c) 2014-2015 Julien Martin
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#import <UIKit/UIKit.h>
#import "MGCDateRange.h"
@class MGCEventView;
@protocol MGCMonthPlannerViewDataSource;
@protocol MGCMonthPlannerViewDelegate;
typedef NS_OPTIONS(NSUInteger, MGCMonthHeaderStyle) {
MGCMonthHeaderStyleDefault = 0,
MGCMonthHeaderStyleShort = 1 << 0,
MGCMonthHeaderStyleHidden = 1 << 1
};
typedef NS_OPTIONS(NSUInteger, MGCMonthPlannerGridStyle) {
MGCMonthPlannerGridStyleFill = 1 << 0,
MGCMonthPlannerGridStyleVerticalLines = 1 << 1,
MGCMonthPlannerGridStyleHorizontalLines = 1 << 2,
MGCMonthPlannerGridStyleBottomDayLabel = 1 << 3,
MGCMonthPlannerGridStyleDefault = (MGCMonthPlannerGridStyleHorizontalLines|MGCMonthPlannerGridStyleVerticalLines)
};
typedef NS_ENUM(NSUInteger, MGCMonthPlannerStyle) {
MGCMonthPlannerStyleEvents = 0,
MGCMonthPlannerStyleDots = 1,
MGCMonthPlannerStyleEmpty = 2
};
typedef NS_ENUM(NSUInteger, MGCMonthPlannerPagingMode) {
MGCMonthPlannerPagingModeNone = 0,
MGCMonthPlannerPagingModeHeaderTop = 1,
MGCMonthPlannerPagingModeHeaderBottom = 2
};
typedef NS_ENUM(NSUInteger, MGCMonthPlannerScrollAlignment) {
MGCMonthPlannerScrollAlignmentHeaderTop = 0,
MGCMonthPlannerScrollAlignmentHeaderBottom = 1,
MGCMonthPlannerScrollAlignmentWeekRow = 2
};
/*!
* MGCMonthPlannerView is a view similar to the month view in the Calendar app on iOS.
*/
@interface MGCMonthPlannerView : UIView
/*!
@group Configuration and appearance customization
*/
/*!
@abstract The calendar used for formatting the months and dates.
@discussion The default value is the logical calendar for the current user (as returned by `[NSCalendar currentCalendar]`)
*/
@property (nonatomic) NSCalendar *calendar;
/*!
@abstract Returns the height of a row of days in the month planner view.
@discussion The default value is 140.
*/
@property (nonatomic) CGFloat rowHeight;
/*!
@abstract Returns the height of the header showing days of week.
@discussion The default value is 35.
It can be set to 0 to hide the header.
*/
@property (nonatomic) CGFloat headerHeight;
/*!
@abstract Returns the height of the header in day cells which displays the date.
@discussion The default value is 30.
*/
@property (nonatomic) CGFloat dayCellHeaderHeight;
/*!
@abstract The distance between each months and between the months and the edge of the view.
*/
@property (nonatomic) UIEdgeInsets monthInsets;
/*!
@abstract Returns the style for the months headers.
@discussion If set to MGCMonthHeaderStyleDefault, the header displays the month name and the year.
If set to MGCMonthHeaderStyleShort, the header only displays the month name.
If set to MGCMonthHeaderStyleHidden, the header is hidden
@discussion The alignment of the header changes depending on the value of the gridStyle property.
@see gridStyle
*/
@property (nonatomic) MGCMonthHeaderStyle monthHeaderStyle;
/*!
@abstract Returns the style of the month planner view.
@discussion If set to MGCMonthPlannerStyleEvents, the view displays events cells, similar to the month view in Apple's Calendar app on iPad.
If set to MGCMonthPlannerStyleDots, the view only displays dots for days with events, similar to the month view in Apple's Calendar app on iPhone.
If set to MGCMonthPlannerStyleEmpty, the view does not display events nor dots.
@discussion The default value is MGCMonthPlannerStyleEvents on regular horizontal size, MGCMonthPlannerStyleDots otherwise.
*/
@property (nonatomic) MGCMonthPlannerStyle style;
/*!
@abstract Returns the color of the dot displayed when the month planner view style is set to MGCMonthPlannerStyleDots.
*/
@property (nonatomic) UIColor *eventsDotColor;
/*!
@abstract Returns the style of the months' background grid.
@discussion If MGCMonthPlannerGridStyleFill is set, the view fills the grid for the first and last week of the month, and the month header, if displayed, is center-aligned.
Otherwise, the grid covers only the days of the months, and the month header, if displayed, is aligned on the first day.
*/
@property (nonatomic) MGCMonthPlannerGridStyle gridStyle;
/*!
@abstract String format for dates displayed on top of day cells.
@discussion If the value of this property is nil, a default format is used according to the current locale.
@see NSDateFormatter dateFormat
@see monthPlannerView:attributedStringForDayHeaderAtDate: delegate method
*/
@property (nonatomic, copy) NSString *dateFormat;
/*!
@abstract Returns the height of event cells.
@discussion The default value is 16.
*/
@property (nonatomic) CGFloat itemHeight;
/*!
@abstract Background color for the whole calendar.
@discussion The default color is white.
*/
@property (nonatomic, strong) UIColor *calendarBackgroundColor;
/*!
@abstract Background color for weekday cells.
@discussion The default color is white.
*/
@property (nonatomic, strong) UIColor *weekDayBackgroundColor;
/*!
@abstract Background color for weekend day cells.
@discussion The default color is light transparent gray.
*/
@property (nonatomic, strong) UIColor *weekendDayBackgroundColor;
/*!
@abstract Text color for the weekday headers on the top of the view.
@discussion The default color is black.
*/
@property (nonatomic, strong) UIColor *weekdaysLabelTextColor;
/*!
@abstract Font used for the weekday headers.
*/
@property (nonatomic, strong) UIFont *weekdaysLabelFont;
/*!
@abstract Array of strings displayed for the weekday headers.
@discussion String at index 0 is for Sunday
@discussion If set to nil, default weekday abbreviations are used (like Mon. or M for Monday, depending of the available size)
*/
@property (nonatomic, strong) NSArray *weekDaysStringArray;
/*!
@abstract Text color for the month headers.
@discussion The default color is black.
@see monthHeaderStyle
*/
@property (nonatomic, strong) UIColor *monthLabelTextColor;
/*!
@abstract Font used for the month headers.
@discussion default is [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]
@see monthHeaderStyle
*/
@property (nonatomic, strong) UIFont *monthLabelFont;
/*!
@abstract Determines whether an event can be created with a long-press on the view.
@discussion The default value is YES. This has no effect if the style property of the view is not set to MGCMonthPlannerStyleEvents.
*/
@property (nonatomic) BOOL canCreateEvents;
/*!
@abstract Determines whether an event can be moved around after a long-press on the view.
@discussion The default value is YES. This has no effect if the style property of the view is not set to MGCMonthPlannerStyleEvents.
*/
@property (nonatomic) BOOL canMoveEvents;
/*!
@abstract The object that provides the data for the month planner view
@discussion The data source must adopt the `MGCMonthPlannerViewDataSource` protocol.
The month planner view view maintains a weak reference to the data source object.
*/
@property (nonatomic, weak) id<MGCMonthPlannerViewDataSource> dataSource;
/*!
@abstract The object acting as the delegate of the month planner View.
@discussion The delegate must adopt the `MGCMonthPlannerViewDelegate` protocol.
The Calendar View maintains a weak reference to the delegate object.
*/
@property (nonatomic, weak) id<MGCMonthPlannerViewDelegate> delegate;
/*!
@abstract Scrollable range of months. Default is nil, for 'infinite' scrolling.
@discussion The range start date is set to the first day of the month, range end to the first day of the month followind end.
@discussion If the currently visible month is outside the new range, the view scrolls to the range starting date.
*/
@property (nonatomic, copy) MGCDateRange *dateRange;
/*!
@group Creating event views
*/
/*!
@abstract Registers a class for use in creating new event views for the month planner view.
@param viewClass The class of the view that you want to use.
@param reuseIdentifier The reuse identifier to associate with the specified class.
This parameter must not be nil and must not be an empty string.
@discussion Prior to calling the dequeueReusableCellWithIdentifier:forEventAtIndex:date: method, you must use this method to tell the month planner how to create a new event view.
*/
- (void)registerClass:(Class)viewClass forEventCellReuseIdentifier:(NSString*)reuseIdentifier;
/*!
@abstract Returns a reusable event view object located by its identifier.
@param reuseIdentifier A string identifying the view object to be reused. This parameter must not be nil.
@param index The index of the event.
@param date The date of the event.
@return A valid MGCEventView object.
@discussion Call this method from your data source object when asked to provide a new event view for the month planner. This method dequeues an existing view if one is available or creates a new one based on the class you previously registered.
@warning You must register a class using the registerClass:forEventCellReuseIdentifier: method before calling this method.
*/
- (MGCEventView*)dequeueReusableCellWithIdentifier:(NSString*)reuseIdentifier forEventAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@group Scrolling and navigation
*/
/*!
@abstract The paging style for the view.
@discussion If set MGCMonthPlannerPagingModeNone, paging is disabled.
If set to MGCMonthPlannerPagingModeHeaderBottom, scrolling stops below the header.
If set to MGCMonthPlannerPagingModeHeaderTop, scrolling stops above the header.
*/
@property (nonatomic) MGCMonthPlannerPagingMode pagingMode;
// deprecated: use scrollToDate:position:animated: instead
- (void)scrollToDate:(NSDate*)date animated:(BOOL)animated;
/*!
@abstract Scrolls the view to make a given date visible.
@param date The date to scroll into view.
@param alignment If set to MGCMonthPlannerScrollAlignmentWeekRow, the top of the view is aligned with the week row for given date.
If set to MGCMonthPlannerScrollAlignmentHeaderBottom, it is aligned with the first row of the month.
If set to MGCMonthPlannerScrollAlignmentHeaderTop, it is aligned with the top of the month header.
@param animated Specify YES to animate the scrolling behavior or NO to adjust the visible content immediately.
@warning If `date` param is not in the scrollable range of dates, an exception is thrown.
*/
- (void)scrollToDate:(NSDate*)date alignment:(MGCMonthPlannerScrollAlignment)alignment animated:(BOOL)animated;
/*!
@group Locating days and events
*/
/*!
@abstract Returns the date range of all visible days.
@discussion Returns nil if no days are shown.
*/
@property (nonatomic, readonly) MGCDateRange *visibleDays;
/*!
@abstract Returns an array of all visible event views currently displayed by the month planner.
@return An array of MGCEventView objects. If no event view is visible, this method returns an empty array.
*/
- (NSArray*)visibleEventCells;
/*!
@abstract Returns the visible event view with specified index and date.
@param index The index of the event.
@param date The date of the event.
@return The event view or nil if the event view is not visible, or parameters are out of range.
*/
- (MGCEventView*)cellForEventAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@abstract Returns the event view at the specified point in the month planner view.
@param pt A point in the month planner view’s coordinate system.
@param date If not nil, it will contain on return the date of the event located at point.
@param index If not nil, it will contain on return the index of the event located at point.
@return The event view at the specified point, or nil if no event was found at the specified point.
*/
- (MGCEventView*)eventCellAtPoint:(CGPoint)pt date:(NSDate**)date index:(NSUInteger*)index;
/*!
@abstract Returns the date at the specified point in the month planner view.
@param pt A point in the month planner view’s coordinate system.
@return The date at the specified point, or nil if the date can't be determined.
*/
- (NSDate*)dayAtPoint:(CGPoint)pt;
/*!
@group Reloading events
*/
/*!
@abstract Reloads all events in the month planner view.
@discussion The view discards any currently displayed visible event views and redisplays them.
*/
- (void)reloadEvents;
/*!
@abstract Reloads all events for given date.
@param date The date for which to reload events.
@discussion The view discards any currently displayed visible event views at date and redisplays them.
*/
- (void)reloadEventsAtDate:(NSDate*)date;
/*!
@abstract Reloads all events in given date range.
@param range Range in which events should be reloaded.
@discussion The view discards any currently displayed visible event views in the range and redisplays them.
*/
- (void)reloadEventsInRange:(MGCDateRange*)range;
/*!
@group Managing the selection
*/
/*!
@abstract Determines whether users can select events in the month planner view.
@discussion The default value is YES.
For more control over the selection of items, you can provide a delegate object and implement the
monthPlannerView:shouldSelectEventAtIndex:date: methods of the MGCMonthPlannerViewDelegate protocol.
*/
@property (nonatomic) BOOL allowsSelection;
/*!
@abstract Returns the date of the selected event, or nil if no event is selected.
*/
@property (nonatomic, readonly) NSDate *selectedEventDate;
/*!
@abstract Returns the index of the selected event at the date given by selectedEventDate.
*/
@property (nonatomic, readonly) NSUInteger selectedEventIndex;
/*!
@abstract Returns the event view for the current selection, or nil if no event is selected.
*/
@property (nonatomic, readonly) MGCEventView *selectedEventView;
/*!
@abstract Selects the visible event view at specified index and date.
@param index The index of the event.
@param date The date of the event.
@discussion If the allowsSelection property is NO, calling this method has no effect.
If there is an existing selection, calling this method replaces the previous selection.
@discussion This method does not cause any selection-related delegate methods to be called.
*/
- (void)selectEventCellAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@abstract Cancels current selection.
@discussion If the allowsSelection property is NO, calling this method has no effect.
@discussion This method does not cause any selection-related delegate methods to be called.
*/
- (void)deselectEvent;
/*!
@abstract Call this method to hide the interactive cell, after an existing event or a new one has been dragged around.
*/
- (void)endInteraction;
@end
//////////////////////////////////////////////////////////////////////////////////////////////
// MGCMonthPlannerViewDataSource
/*!
* An object that adopts the MGCMonthPlannerViewDataSource protocol is responsible for providing the data and views
* required by a month planner view.
*/
@protocol MGCMonthPlannerViewDataSource<NSObject>
@required
/*!
@abstract Asks the data source for the number of events at specified date. (required)
*/
- (NSInteger)monthPlannerView:(MGCMonthPlannerView*)view numberOfEventsAtDate:(NSDate*)date;
/*!
@abstract Asks the data source for the date range of the specified event in the month planner view. (required)
*/
- (MGCDateRange*)monthPlannerView:(MGCMonthPlannerView*)view dateRangeForEventAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@abstract Asks the data source for the view that corresponds to the specified event in the month planner view. (required)
*/
- (MGCEventView*)monthPlannerView:(MGCMonthPlannerView*)view cellForEventAtIndex:(NSUInteger)index date:(NSDate*)date;
@optional
/*!
@abstract Asks the data source for the view to be displayed when a new event is about to be created.
@discussion If this method is not implemented by the data source, a standard event view will be used.
*/
- (MGCEventView*)monthPlannerView:(MGCMonthPlannerView *)view cellForNewEventAtDate:(NSDate*)date;
/*!
@abstract Asks the data source if the specified event can be moved around. If the method returns YES, the
event view can be dragged and dropped to a different date.
@discussion This method is not called if month planner view's canMoveEvents property is set to NO.
*/
- (BOOL)monthPlannerView:(MGCMonthPlannerView*)view canMoveCellForEventAtIndex:(NSUInteger)index date:(NSDate*)date;
@end
/*!
* The MGCMonthPlannerViewDelegate protocol defines methods that allow you to manage the selection of events in
* a month planner view and respond to operations like scrolling and changes in the display.
* The methods of this protocol are all optional.
*/
@protocol MGCMonthPlannerViewDelegate<NSObject>
@optional
/*!
@abstract Asks the delegate for the attributed string of the day header for given date.
@param view The month planner view requesting the information.
@param date The date for the header.
@return The attributed string to draw.
*/
- (NSAttributedString*)monthPlannerView:(MGCMonthPlannerView*)view attributedStringForDayHeaderAtDate:(NSDate*)date;
/*!
@abstract Tells the delegate that the month planner view was scrolled.
*/
- (void)monthPlannerViewDidScroll:(MGCMonthPlannerView*)view;
/*!
@abstract Tells the delegate that a day cell was selected.
@param view The month planner view object notifying about the selection change.
@param date The date for the corresponding cell.
*/
- (void)monthPlannerView:(MGCMonthPlannerView*)view didSelectDayCellAtDate:(NSDate*)date;
/*!
@abstract Tells the delegate that a day cell was selected.
@param view The month planner view object notifying about the selection change.
@param date The date for the corresponding cell.
*/
- (void)monthPlannerView:(MGCMonthPlannerView*)view didShowCell:(MGCEventView*)cell forNewEventAtDate:(NSDate*)date;
- (void)monthPlannerView:(MGCMonthPlannerView*)view willStartMovingEventAtIndex:(NSUInteger)index date:(NSDate*)date;
- (void)monthPlannerView:(MGCMonthPlannerView*)view didMoveEventAtIndex:(NSUInteger)index date:(NSDate*)dateOld toDate:(NSDate*)dayNew;
/*!
@group Managing the selection of events
*/
/*!
@abstract Asks the delegate if the specified event should be selected.
@param view The month planner view object making the request.
@param index The index of the event.
@param date The day of the event.
@return YES if the event should be selected or NO if it should not.
@discussion The month planner view calls this method when the user tries to select an event.
It does not call this method when you programmatically set the selection.
@discussion If you do not implement this method, the default return value is YES.
*/
- (BOOL)monthPlannerView:(MGCMonthPlannerView*)view shouldSelectEventAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@abstract Tells the delegate that the specified event was selected.
@param view The month planner view object notifying about the selection change.
@param index The index of the event.
@param date The day of the event.
@discussion The month planner view calls this method when the user successfully selects an event.
It does not call this method when you programmatically set the selection.
*/
- (void)monthPlannerView:(MGCMonthPlannerView*)view didSelectEventAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@abstract Asks the delegate if the specified event should be deselected.
@param view The month planner view object notifying about the selection change.
@param index The index of the event.
@param date The day of the event.
@return YES if the event should be selected or NO if it should not.
@discussion The month planner view calls this method when the user tries to deselect an already selected event.
It does not call this method when you programmatically set the selection.
*/
- (BOOL)monthPlannerView:(MGCMonthPlannerView*)view shouldDeselectEventAtIndex:(NSUInteger)index date:(NSDate*)date;
/*!
@abstract Tells the delegate that the specified event was deselected.
@param view The month planner view object notifying about the selection change.
@param index The index of the event.
@param date The day of the event.
@discussion This does not get called when you programmatically deselect an event with the deselectEvent method
*/
- (void)monthPlannerView:(MGCMonthPlannerView*)view didDeselectEventAtIndex:(NSUInteger)index date:(NSDate*)date;
@end