forked from objcio/issue-3-collection-view-layouts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florian Kugler
committed
Aug 8, 2013
0 parents
commit 21b5b35
Showing
27 changed files
with
1,523 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.DS_Store | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
*.xcworkspace | ||
!default.xcworkspace | ||
xcuserdata | ||
profile | ||
*.moved-aside | ||
DerivedData | ||
.idea/ | ||
Pods/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// AppDelegate.h | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface AppDelegate : UIResponder <UIApplicationDelegate> | ||
|
||
@property (strong, nonatomic) UIWindow *window; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// AppDelegate.m | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import "AppDelegate.h" | ||
|
||
@implementation AppDelegate | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | ||
{ | ||
return YES; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleDisplayName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundleExecutable</key> | ||
<string>${EXECUTABLE_NAME}</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>com.olebegemann.${PRODUCT_NAME:rfc1034identifier}</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>${PRODUCT_NAME}</string> | ||
<key>CFBundlePackageType</key> | ||
<string>APPL</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>1.0</string> | ||
<key>LSRequiresIPhoneOS</key> | ||
<true/> | ||
<key>UIMainStoryboardFile</key> | ||
<string>MainStoryboard</string> | ||
<key>UIRequiredDeviceCapabilities</key> | ||
<array> | ||
<string>armv7</string> | ||
</array> | ||
<key>UISupportedInterfaceOrientations~ipad</key> | ||
<array> | ||
<string>UIInterfaceOrientationPortrait</string> | ||
<string>UIInterfaceOrientationPortraitUpsideDown</string> | ||
<string>UIInterfaceOrientationLandscapeLeft</string> | ||
<string>UIInterfaceOrientationLandscapeRight</string> | ||
</array> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Prefix header for all source files of the 'Calendar' target in the 'Calendar' project | ||
// | ||
|
||
#import <Availability.h> | ||
|
||
#ifndef __IPHONE_5_0 | ||
#warning "This project uses features only available in iOS SDK 5.0 and later." | ||
#endif | ||
|
||
#ifdef __OBJC__ | ||
#import <UIKit/UIKit.h> | ||
#import <Foundation/Foundation.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// CalendarDataSource.h | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "CalendarEvent.h" | ||
#import "CalendarEventCell.h" | ||
#import "HeaderView.h" | ||
|
||
typedef void (^ConfigureCellBlock)(CalendarEventCell *cell, NSIndexPath *indexPath, id<CalendarEvent> event); | ||
typedef void (^ConfigureHeaderViewBlock)(HeaderView *headerView, NSString *kind, NSIndexPath *indexPath); | ||
|
||
@interface CalendarDataSource : NSObject <UICollectionViewDataSource> | ||
|
||
@property (copy, nonatomic) ConfigureCellBlock configureCellBlock; | ||
@property (copy, nonatomic) ConfigureHeaderViewBlock configureHeaderViewBlock; | ||
|
||
- (id<CalendarEvent>)eventAtIndexPath:(NSIndexPath *)indexPath; | ||
- (NSArray *)indexPathsOfEventsBetweenMinDayIndex:(NSInteger)minDayIndex maxDayIndex:(NSInteger)maxDayIndex minStartHour:(NSInteger)minStartHour maxStartHour:(NSInteger)maxStartHour; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// | ||
// CalendarDataSource.m | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import "CalendarDataSource.h" | ||
#import "SampleCalendarEvent.h" | ||
|
||
@interface CalendarDataSource () | ||
|
||
@property (strong, nonatomic) NSMutableArray *events; | ||
|
||
@end | ||
|
||
@implementation CalendarDataSource | ||
|
||
- (void)awakeFromNib | ||
{ | ||
_events = [[NSMutableArray alloc] init]; | ||
|
||
// Prepare some example events | ||
// In a real app, these should be retrieved from the calendar data store (EventKit.framework) | ||
// We use a very simple data format for our events. In a real calendar app, event times should be | ||
// represented with NSDate objects and correct calendrical date calculcations should be used. | ||
[self generateSampleData]; | ||
} | ||
|
||
- (void)generateSampleData | ||
{ | ||
for (NSUInteger idx = 0; idx < 20; idx++) { | ||
SampleCalendarEvent *event = [SampleCalendarEvent randomEvent]; | ||
[self.events addObject:event]; | ||
} | ||
} | ||
|
||
#pragma mark - CalendarDataSource | ||
|
||
// The layout object calls these methods to identify the events that correspond to | ||
// a given index path or that are visible in a certain rectangle | ||
|
||
- (id<CalendarEvent>)eventAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
return self.events[indexPath.item]; | ||
} | ||
|
||
- (NSArray *)indexPathsOfEventsBetweenMinDayIndex:(NSInteger)minDayIndex maxDayIndex:(NSInteger)maxDayIndex minStartHour:(NSInteger)minStartHour maxStartHour:(NSInteger)maxStartHour | ||
{ | ||
NSMutableArray *indexPaths = [NSMutableArray array]; | ||
[self.events enumerateObjectsUsingBlock:^(id event, NSUInteger idx, BOOL *stop) { | ||
if ([event day] >= minDayIndex && [event day] <= maxDayIndex && [event startHour] >= minStartHour && [event startHour] <= maxStartHour) | ||
{ | ||
NSIndexPath *indexPath = [NSIndexPath indexPathForItem:idx inSection:0]; | ||
[indexPaths addObject:indexPath]; | ||
} | ||
}]; | ||
return indexPaths; | ||
} | ||
|
||
#pragma mark - UICollectionViewDataSource | ||
|
||
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section | ||
{ | ||
return [self.events count]; | ||
} | ||
|
||
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
id<CalendarEvent> event = self.events[indexPath.item]; | ||
CalendarEventCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CalendarEventCell" forIndexPath:indexPath]; | ||
|
||
if (self.configureCellBlock) { | ||
self.configureCellBlock(cell, indexPath, event); | ||
} | ||
return cell; | ||
} | ||
|
||
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
HeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"HeaderView" forIndexPath:indexPath]; | ||
if (self.configureHeaderViewBlock) { | ||
self.configureHeaderViewBlock(headerView, kind, indexPath); | ||
} | ||
return headerView; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// CalendarEvent.h | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@protocol CalendarEvent <NSObject> | ||
|
||
@property (copy, nonatomic) NSString *title; | ||
@property (assign, nonatomic) NSInteger day; | ||
@property (assign, nonatomic) NSInteger startHour; | ||
@property (assign, nonatomic) NSInteger durationInHours; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// CalendarEventCell.h | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface CalendarEventCell : UICollectionViewCell | ||
|
||
@property (weak, nonatomic) IBOutlet UILabel *titleLabel; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// CalendarEventCell.m | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <QuartzCore/QuartzCore.h> | ||
#import "CalendarEventCell.h" | ||
|
||
@implementation CalendarEventCell | ||
|
||
- (id)initWithFrame:(CGRect)frame | ||
{ | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
[self setup]; | ||
} | ||
return self; | ||
} | ||
|
||
- (id)initWithCoder:(NSCoder *)decoder | ||
{ | ||
self = [super initWithCoder:decoder]; | ||
if (self) { | ||
[self setup]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setup | ||
{ | ||
self.layer.cornerRadius = 10; | ||
self.layer.borderWidth = 1.0; | ||
self.layer.borderColor = [[UIColor colorWithRed:0 green:0 blue:0.7 alpha:1] CGColor]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// CalendarViewController.h | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface CalendarViewController : UICollectionViewController | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// CalendarViewController.m | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import "CalendarViewController.h" | ||
#import "CalendarDataSource.h" | ||
#import "HeaderView.h" | ||
|
||
@interface CalendarViewController () | ||
|
||
@property (strong, nonatomic) IBOutlet CalendarDataSource *calendarDataSource; | ||
|
||
@end | ||
|
||
@implementation CalendarViewController | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
|
||
// Register NIB for supplementary views | ||
UINib *headerViewNib = [UINib nibWithNibName:@"HeaderView" bundle:nil]; | ||
[self.collectionView registerNib:headerViewNib forSupplementaryViewOfKind:@"DayHeaderView" withReuseIdentifier:@"HeaderView"]; | ||
[self.collectionView registerNib:headerViewNib forSupplementaryViewOfKind:@"HourHeaderView" withReuseIdentifier:@"HeaderView"]; | ||
|
||
// Define cell and header view configuration | ||
CalendarDataSource *dataSource = (CalendarDataSource *)self.collectionView.dataSource; | ||
dataSource.configureCellBlock = ^(CalendarEventCell *cell, NSIndexPath *indexPath, id<CalendarEvent> event) { | ||
cell.titleLabel.text = event.title; | ||
}; | ||
dataSource.configureHeaderViewBlock = ^(HeaderView *headerView, NSString *kind, NSIndexPath *indexPath) { | ||
if ([kind isEqualToString:@"DayHeaderView"]) { | ||
headerView.titleLabel.text = [NSString stringWithFormat:@"Day %d", indexPath.item + 1]; | ||
} else if ([kind isEqualToString:@"HourHeaderView"]) { | ||
headerView.titleLabel.text = [NSString stringWithFormat:@"%2d:00", indexPath.item + 1]; | ||
} | ||
}; | ||
} | ||
|
||
@end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// HeaderView.h | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface HeaderView : UICollectionReusableView | ||
|
||
@property (weak, nonatomic) IBOutlet UILabel *titleLabel; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// HeaderView.m | ||
// Calendar | ||
// | ||
// Created by Ole Begemann on 29.07.13. | ||
// Copyright (c) 2013 Ole Begemann. All rights reserved. | ||
// | ||
|
||
#import "HeaderView.h" | ||
|
||
@implementation HeaderView | ||
|
||
@end |
Oops, something went wrong.