Skip to content

Instantly share code, notes, and snippets.

@jverkoey
Created June 23, 2012 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jverkoey/2977488 to your computer and use it in GitHub Desktop.
Save jverkoey/2977488 to your computer and use it in GitHub Desktop.
NILauncherModel Example 1
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Load the Nimbus app icon.
NSString* imagePath = NIPathForBundleResource(nil, @"Icon.png");
UIImage* image = [[Nimbus imageMemoryCache] objectWithName:imagePath];
if (nil == image) {
image = [UIImage imageWithContentsOfFile:imagePath];
[[Nimbus imageMemoryCache] storeObject:image withName:imagePath];
}
// We populate the launcher model with an array of arrays of NILauncherViewObject objects.
// Each sub array is a single page of the launcher view. The default NILauncherViewObject object
// allows you to provide a title and image.
NSArray* contents =
[NSArray arrayWithObjects:
[NSArray arrayWithObjects:
[NILauncherViewObject objectWithTitle:@"Nimbus" image:image],
[NILauncherViewObject objectWithTitle:@"Nimbus 2" image:image],
[NILauncherViewObject objectWithTitle:@"Nimbus 3" image:image],
[NILauncherViewObject objectWithTitle:@"Nimbus 5" image:image],
[NILauncherViewObject objectWithTitle:@"Nimbus 6" image:image],
nil],
// A new page.
[NSArray arrayWithObjects:
[NILauncherViewObject objectWithTitle:@"Page 2" image:image],
nil],
// A third page.
[NSArray arrayWithObjects:
[NILauncherViewObject objectWithTitle:@"Page 3" image:image],
nil],
nil];
// Create the model object with the contents array. We provide self as the delegate so that
// we can customize what the buttons look like.
_model = [[NILauncherViewModel alloc] initWithArrayOfPages:contents delegate:self];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor underPageBackgroundColor];
// Because the model implements the NILauncherViewDataSource protocol we can simply assign the
// model to the dataSource property and everything will magically work. Wicked!
self.launcherView.dataSource = self.model;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment