forked from boctor/idev-recipes
-
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
Showing
29 changed files
with
2,117 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,17 @@ | ||
// | ||
// RootViewController.h | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
#import "SideSwipeTableViewController.h" | ||
|
||
@interface RootViewController : SideSwipeTableViewController | ||
{ | ||
NSArray* buttonData; | ||
NSMutableArray* buttons; | ||
} | ||
|
||
@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,163 @@ | ||
// | ||
// RootViewController.m | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
#import "RootViewController.h" | ||
#import "SideSwipeTableViewCell.h" | ||
#import <QuartzCore/QuartzCore.h> | ||
|
||
#define BUTTON_LEFT_MARGIN 10.0 | ||
#define BUTTON_SPACING 25.0 | ||
|
||
@interface RootViewController (PrivateStuff) | ||
-(void) setupSideSwipeView; | ||
-(UIImage*) imageFilledWith:(UIColor*)color using:(UIImage*)startImage; | ||
@end | ||
|
||
@implementation RootViewController | ||
|
||
- (void)viewDidLoad | ||
{ | ||
[super viewDidLoad]; | ||
|
||
// Setup the title and image for each button within the side swipe view | ||
buttonData = [[NSArray arrayWithObjects: | ||
[NSDictionary dictionaryWithObjectsAndKeys:@"Reply", @"title", @"reply.png", @"image", nil], | ||
[NSDictionary dictionaryWithObjectsAndKeys:@"Retweet", @"title", @"retweet-outline-button-item.png", @"image", nil], | ||
[NSDictionary dictionaryWithObjectsAndKeys:@"Favorite", @"title", @"star-hollow.png", @"image", nil], | ||
[NSDictionary dictionaryWithObjectsAndKeys:@"Profile", @"title", @"person.png", @"image", nil], | ||
[NSDictionary dictionaryWithObjectsAndKeys:@"Links", @"title", @"paperclip.png", @"image", nil], | ||
[NSDictionary dictionaryWithObjectsAndKeys:@"Action", @"title", @"action.png", @"image", nil], | ||
nil] retain]; | ||
buttons = [[NSMutableArray alloc] initWithCapacity:buttonData.count]; | ||
|
||
self.sideSwipeView = [[[UIView alloc] initWithFrame:CGRectMake(tableView.frame.origin.x, tableView.frame.origin.y, tableView.frame.size.width, tableView.rowHeight)] autorelease]; | ||
[self setupSideSwipeView]; | ||
} | ||
|
||
- (void) setupSideSwipeView | ||
{ | ||
// Add the background pattern | ||
self.sideSwipeView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"dotted-pattern.png"]]; | ||
|
||
// Overlay a shadow image that adds a subtle darker drop shadow around the edges | ||
UIImage* shadow = [[UIImage imageNamed:@"inner-shadow.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0]; | ||
UIImageView* shadowImageView = [[[UIImageView alloc] initWithFrame:sideSwipeView.frame] autorelease]; | ||
shadowImageView.alpha = 0.6; | ||
shadowImageView.image = shadow; | ||
shadowImageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | ||
[self.sideSwipeView addSubview:shadowImageView]; | ||
|
||
// Iterate through the button data and create a button for each entry | ||
CGFloat leftEdge = BUTTON_LEFT_MARGIN; | ||
for (NSDictionary* buttonInfo in buttonData) | ||
{ | ||
// Create the button | ||
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; | ||
|
||
// Make sure the button ends up in the right place when the cell is resized | ||
button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; | ||
|
||
// Get the button image | ||
UIImage* buttonImage = [UIImage imageNamed:[buttonInfo objectForKey:@"image"]]; | ||
|
||
// Set the button's frame | ||
button.frame = CGRectMake(leftEdge, sideSwipeView.center.y - buttonImage.size.height/2.0, buttonImage.size.width, buttonImage.size.height); | ||
|
||
// Add the image as the button's background image | ||
// [button setBackgroundImage:buttonImage forState:UIControlStateNormal]; | ||
UIImage* grayImage = [self imageFilledWith:[UIColor colorWithWhite:0.9 alpha:1.0] using:buttonImage]; | ||
[button setImage:grayImage forState:UIControlStateNormal]; | ||
|
||
// Add a touch up inside action | ||
[button addTarget:self action:@selector(touchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside]; | ||
|
||
// Keep track of the buttons so we know the proper text to display in the touch up inside action | ||
[buttons addObject:button]; | ||
|
||
// Add the button to the side swipe view | ||
[self.sideSwipeView addSubview:button]; | ||
|
||
// Move the left edge in prepartion for the next button | ||
leftEdge = leftEdge + buttonImage.size.width + BUTTON_SPACING; | ||
} | ||
} | ||
|
||
#pragma mark UITableViewDataSource | ||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | ||
{ | ||
return 10; | ||
} | ||
|
||
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
static NSString *CellIdentifier = @"Cell"; | ||
|
||
SideSwipeTableViewCell *cell = (SideSwipeTableViewCell*)[theTableView dequeueReusableCellWithIdentifier:CellIdentifier]; | ||
if (cell == nil) | ||
cell = [[[SideSwipeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; | ||
|
||
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; | ||
cell.supressDeleteButton = ![self gestureRecognizersSupported]; | ||
return cell; | ||
} | ||
|
||
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
return 44 + indexPath.row * 5; | ||
} | ||
|
||
#pragma mark Button touch up inside action | ||
- (IBAction) touchUpInsideAction:(UIButton*)button | ||
{ | ||
NSUInteger index = [buttons indexOfObject:button]; | ||
NSDictionary* buttonInfo = [buttonData objectAtIndex:index]; | ||
[[[[UIAlertView alloc] initWithTitle:[buttonInfo objectForKey:@"title"] | ||
message:nil | ||
delegate:nil | ||
cancelButtonTitle:nil | ||
otherButtonTitles:@"OK", nil] autorelease] show]; | ||
|
||
[self removeSideSwipeView:YES]; | ||
} | ||
|
||
#pragma mark Generate images with given fill color | ||
// Convert the image's fill color to the passed in color | ||
-(UIImage*) imageFilledWith:(UIColor*)color using:(UIImage*)startImage | ||
{ | ||
// Create the proper sized rect | ||
CGRect imageRect = CGRectMake(0, 0, CGImageGetWidth(startImage.CGImage), CGImageGetHeight(startImage.CGImage)); | ||
|
||
// Create a new bitmap context | ||
CGContextRef context = CGBitmapContextCreate(NULL, imageRect.size.width, imageRect.size.height, 8, 0, CGImageGetColorSpace(startImage.CGImage), kCGImageAlphaPremultipliedLast); | ||
|
||
// Use the passed in image as a clipping mask | ||
CGContextClipToMask(context, imageRect, startImage.CGImage); | ||
// Set the fill color | ||
CGContextSetFillColorWithColor(context, color.CGColor); | ||
// Fill with color | ||
CGContextFillRect(context, imageRect); | ||
|
||
// Generate a new image | ||
CGImageRef newCGImage = CGBitmapContextCreateImage(context); | ||
UIImage* newImage = [UIImage imageWithCGImage:newCGImage scale:startImage.scale orientation:startImage.imageOrientation]; | ||
|
||
// Cleanup | ||
CGContextRelease(context); | ||
CGImageRelease(newCGImage); | ||
|
||
return newImage; | ||
} | ||
|
||
- (void)dealloc | ||
{ | ||
[buttons release]; | ||
[buttonData release]; | ||
[super dealloc]; | ||
} | ||
|
||
@end |
21 changes: 21 additions & 0 deletions
21
SideSwipeTableView/Classes/SideSwipeTableViewAppDelegate.h
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,21 @@ | ||
// | ||
// SideSwipeTableViewAppDelegate.h | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface SideSwipeTableViewAppDelegate : NSObject <UIApplicationDelegate> { | ||
|
||
UIWindow *window; | ||
UINavigationController *navigationController; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UIWindow *window; | ||
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; | ||
|
||
@end | ||
|
90 changes: 90 additions & 0 deletions
90
SideSwipeTableView/Classes/SideSwipeTableViewAppDelegate.m
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,90 @@ | ||
// | ||
// SideSwipeTableViewAppDelegate.m | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
#import "SideSwipeTableViewAppDelegate.h" | ||
#import "RootViewController.h" | ||
|
||
|
||
@implementation SideSwipeTableViewAppDelegate | ||
|
||
@synthesize window; | ||
@synthesize navigationController; | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Application lifecycle | ||
|
||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | ||
|
||
// Override point for customization after application launch. | ||
|
||
// Set the navigation controller as the window's root view controller and display. | ||
self.window.rootViewController = self.navigationController; | ||
[self.window makeKeyAndVisible]; | ||
|
||
return YES; | ||
} | ||
|
||
|
||
- (void)applicationWillResignActive:(UIApplication *)application { | ||
/* | ||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. | ||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. | ||
*/ | ||
} | ||
|
||
|
||
- (void)applicationDidEnterBackground:(UIApplication *)application { | ||
/* | ||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. | ||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits. | ||
*/ | ||
} | ||
|
||
|
||
- (void)applicationWillEnterForeground:(UIApplication *)application { | ||
/* | ||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. | ||
*/ | ||
} | ||
|
||
|
||
- (void)applicationDidBecomeActive:(UIApplication *)application { | ||
/* | ||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. | ||
*/ | ||
} | ||
|
||
|
||
- (void)applicationWillTerminate:(UIApplication *)application { | ||
/* | ||
Called when the application is about to terminate. | ||
See also applicationDidEnterBackground:. | ||
*/ | ||
} | ||
|
||
|
||
#pragma mark - | ||
#pragma mark Memory management | ||
|
||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { | ||
/* | ||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. | ||
*/ | ||
} | ||
|
||
|
||
- (void)dealloc { | ||
[navigationController release]; | ||
[window release]; | ||
[super dealloc]; | ||
} | ||
|
||
|
||
@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,16 @@ | ||
// | ||
// SideSwipeTableViewCell.h | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
@interface SideSwipeTableViewCell : UITableViewCell | ||
{ | ||
BOOL supressDeleteButton; | ||
} | ||
|
||
@property (nonatomic) BOOL supressDeleteButton; | ||
|
||
@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,40 @@ | ||
// | ||
// SideSwipeTableViewCell.m | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
#import "SideSwipeTableViewCell.h" | ||
|
||
@implementation SideSwipeTableViewCell | ||
@synthesize supressDeleteButton; | ||
|
||
// Recursively go up the view hierarchy to find our tableView | ||
-(UITableView*)getTableView:(UIView*)theView | ||
{ | ||
if (!theView.superview) | ||
return nil; | ||
|
||
if ([theView.superview isKindOfClass:[UITableView class]]) | ||
return (UITableView*)theView.superview; | ||
|
||
return [self getTableView:theView.superview]; | ||
} | ||
|
||
- (void)setEditing:(BOOL)editing animated:(BOOL)animated | ||
{ | ||
// We suppress the Delete button by explicitly not calling | ||
// super's implementation | ||
if (supressDeleteButton) | ||
{ | ||
// Reset the editing state of the table back to NO | ||
UITableView* tableView = [self getTableView:self]; | ||
tableView.editing = NO; | ||
} | ||
else | ||
[super setEditing:editing animated:animated]; | ||
} | ||
|
||
@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,28 @@ | ||
// | ||
// SideSwipeTableViewController.h | ||
// SideSwipeTableView | ||
// | ||
// Created by Peter Boctor on 4/13/11. | ||
// Copyright 2011 Peter Boctor. All rights reserved. | ||
// | ||
|
||
|
||
@interface SideSwipeTableViewController : UIViewController | ||
{ | ||
IBOutlet UITableView* tableView; | ||
IBOutlet UIView* sideSwipeView; | ||
UITableViewCell* sideSwipeCell; | ||
UISwipeGestureRecognizerDirection sideSwipeDirection; | ||
BOOL animatingSideSwipe; | ||
} | ||
|
||
@property (nonatomic, retain) IBOutlet UITableView* tableView; | ||
@property (nonatomic, retain) IBOutlet UIView* sideSwipeView; | ||
@property (nonatomic, retain) UITableViewCell* sideSwipeCell; | ||
@property (nonatomic) UISwipeGestureRecognizerDirection sideSwipeDirection; | ||
@property (nonatomic) BOOL animatingSideSwipe; | ||
|
||
- (void) removeSideSwipeView:(BOOL)animated; | ||
- (BOOL) gestureRecognizersSupported; | ||
|
||
@end |
Oops, something went wrong.