Skip to content

Commit

Permalink
- Visual tuning for cell color, status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jamztang committed Feb 15, 2012
1 parent da57bc9 commit 97f80bc
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 11 deletions.
3 changes: 2 additions & 1 deletion JTGestureBasedTableView/TransformableTableViewCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

@interface TransformableTableViewCell : UITableViewCell

@property (nonatomic, assign) CGFloat finishedHeight;
@property (nonatomic, assign) CGFloat finishedHeight;
@property (nonatomic, retain) UIColor *tintColor; // default is white color

@end
15 changes: 11 additions & 4 deletions JTGestureBasedTableView/TransformableTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
*/

#import "TransformableTableViewCell.h"
#import "UIColor+JTGestureBasedTableViewHelper.h"
#import <QuartzCore/QuartzCore.h>

@implementation TransformableTableViewCell

@synthesize finishedHeight;
@synthesize finishedHeight, tintColor;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
Expand All @@ -27,6 +28,11 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus

self.detailTextLabel.layer.anchorPoint = CGPointMake(0.5, 1.0);
self.selectionStyle = UITableViewCellSelectionStyleNone;

self.textLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;
self.detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;

self.tintColor = [UIColor whiteColor];
}
return self;
}
Expand All @@ -49,12 +55,13 @@ - (void)layoutSubviews {
[self.textLabel.layer setTransform:transform];
[self.detailTextLabel.layer setTransform:CATransform3DMakeRotation((M_PI / 2) - asinf(fraction), 1, 0, 0)];

self.textLabel.backgroundColor = [UIColor colorWithWhite:0.65 + 0.3*fraction alpha:1];
self.detailTextLabel.backgroundColor = [UIColor colorWithWhite:0.7 + 0.275*fraction alpha:1];
self.textLabel.backgroundColor = [self.tintColor colorWithBrightness:0.3 + 0.7*fraction];
self.detailTextLabel.backgroundColor = [self.tintColor colorWithBrightness:0.5 + 0.5*fraction];


fraction = 1 / fraction;

CGFloat labelHeight = (int)(self.contentView.frame.size.height/2*fraction + 0.5);
CGFloat labelHeight = ceilf(self.contentView.frame.size.height/2*fraction);
labelHeight = MIN(MAX(1, labelHeight), 800);

self.textLabel.frame = CGRectMake(0, 0, self.contentView.frame.size.width, labelHeight);
Expand Down
15 changes: 15 additions & 0 deletions JTGestureBasedTableView/UIColor+JTGestureBasedTableViewHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This file is part of the JTGestureBasedTableView package.
* (c) James Tang <mystcolor@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import <UIKit/UIKit.h>

@interface UIColor (JTGestureBasedTableViewHelper)
- (UIColor *)colorWithBrightness:(CGFloat)brightness;
- (UIColor *)colorWithHueOffset:(CGFloat)hueOffset;
@end

60 changes: 60 additions & 0 deletions JTGestureBasedTableView/UIColor+JTGestureBasedTableViewHelper.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* This file is part of the JTGestureBasedTableView package.
* (c) James Tang <mystcolor@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import "UIColor+JTGestureBasedTableViewHelper.h"

@implementation UIColor (JTGestureBasedTableViewHelper)
- (UIColor *)colorWithBrightness:(CGFloat)brightnessComponent {

UIColor *newColor = nil;
if ( ! newColor) {
CGFloat hue, saturation, brightness, alpha;
if ([self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]) {
newColor = [UIColor colorWithHue:hue
saturation:saturation
brightness:brightness * brightnessComponent
alpha:alpha];
}
}

if ( ! newColor) {
CGFloat red, green, blue, alpha;
if ([self getRed:&red green:&green blue:&blue alpha:&alpha]) {
newColor = [UIColor colorWithRed:red*brightnessComponent
green:green*brightnessComponent
blue:blue*brightnessComponent
alpha:alpha];
}
}

if ( ! newColor) {
CGFloat white, alpha;
if ([self getWhite:&white alpha:&alpha]) {
newColor = [UIColor colorWithWhite:white * brightnessComponent alpha:alpha];
}
}

return newColor;
}

- (UIColor *)colorWithHueOffset:(CGFloat)hueOffset {
UIColor *newColor = nil;
if ( ! newColor) {
CGFloat hue, saturation, brightness, alpha;
if ([self getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha]) {
// We wants the hue value to be between 0 - 1 after appending the offset
CGFloat newHue = fmodf((hue + hueOffset), 1);
newColor = [UIColor colorWithHue:newHue
saturation:saturation
brightness:brightness
alpha:alpha];
}
}
return newColor;
}
@end
6 changes: 6 additions & 0 deletions JTGestureBasedTableViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
5296DB0C14E977C20044BD53 /* JTTableViewGestureRecognizer.m in Sources */ = {isa = PBXBuildFile; fileRef = 5296DB0914E977C20044BD53 /* JTTableViewGestureRecognizer.m */; };
5296DB0D14E977C20044BD53 /* TransformableTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 5296DB0B14E977C20044BD53 /* TransformableTableViewCell.m */; };
52B4AC6514EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 52B4AC6414EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.m */; };
52D6217D14DF7F1E00400117 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6217C14DF7F1E00400117 /* UIKit.framework */; };
52D6217F14DF7F1E00400117 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6217E14DF7F1E00400117 /* Foundation.framework */; };
52D6218114DF7F1E00400117 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 52D6218014DF7F1E00400117 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -41,6 +42,8 @@
5296DB0914E977C20044BD53 /* JTTableViewGestureRecognizer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JTTableViewGestureRecognizer.m; sourceTree = "<group>"; };
5296DB0A14E977C20044BD53 /* TransformableTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TransformableTableViewCell.h; sourceTree = "<group>"; };
5296DB0B14E977C20044BD53 /* TransformableTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TransformableTableViewCell.m; sourceTree = "<group>"; };
52B4AC6314EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; path = "UIColor+JTGestureBasedTableViewHelper.h"; sourceTree = "<group>"; };
52B4AC6414EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+JTGestureBasedTableViewHelper.m"; sourceTree = "<group>"; };
52D6217814DF7F1E00400117 /* JTGestureBasedTableViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = JTGestureBasedTableViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
52D6217C14DF7F1E00400117 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
52D6217E14DF7F1E00400117 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -96,6 +99,8 @@
5296DB0914E977C20044BD53 /* JTTableViewGestureRecognizer.m */,
5296DB0A14E977C20044BD53 /* TransformableTableViewCell.h */,
5296DB0B14E977C20044BD53 /* TransformableTableViewCell.m */,
52B4AC6314EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.h */,
52B4AC6414EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.m */,
);
path = JTGestureBasedTableView;
sourceTree = "<group>";
Expand Down Expand Up @@ -288,6 +293,7 @@
52D6219014DF7F1E00400117 /* ViewController.m in Sources */,
5296DB0C14E977C20044BD53 /* JTTableViewGestureRecognizer.m in Sources */,
5296DB0D14E977C20044BD53 /* TransformableTableViewCell.m in Sources */,
52B4AC6514EB47AC006574B9 /* UIColor+JTGestureBasedTableViewHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 2 additions & 0 deletions JTGestureBasedTableViewDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Will auto load the corresponding viewController.xib
self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil];

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<array>
<string>armv7</string>
</array>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
24 changes: 18 additions & 6 deletions JTGestureBasedTableViewDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "ViewController.h"
#import "TransformableTableViewCell.h"
#import "JTTableViewGestureRecognizer.h"
#import "UIColor+JTGestureBasedTableViewHelper.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController () <JTTableViewGestureDelegate>
Expand All @@ -30,13 +31,12 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
self.rows = [NSMutableArray arrayWithObjects:
@"Drag down to create a new cell",
@"example cell 1",
@"example cell 2",
@"example cell 3",
@" ",
@" ",
@"Pinch between any cell to create a new one",
@"example cell 4",
@"example cell 5",
@"example cell 6",
@" ",
@" ",
@" ",
nil];
}
return self;
Expand All @@ -48,6 +48,10 @@ - (void)viewDidLoad
// Do any additional setup after loading the view, typically from a nib.

self.tableViewRecognizer = [self.tableView enableGestureTableViewWithDelegate:self];

self.tableView.backgroundColor = [UIColor blackColor];
self.tableView.separatorColor = [UIColor blackColor];
self.tableView.rowHeight = NORMAL_CELL_FINISHING_HEIGHT;
}

#pragma mark UITableViewDatasource
Expand All @@ -67,21 +71,29 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
if (cell == nil) {
cell = [[TransformableTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
cell.textLabel.adjustsFontSizeToFitWidth = YES;
cell.textLabel.textColor = [UIColor whiteColor];
}
NSObject *object = [self.rows objectAtIndex:indexPath.row];

// Setup tint color
cell.tintColor = [[UIColor redColor] colorWithHueOffset:(CGFloat)indexPath.row/100];

if ([object isEqual:ADDING_CELL]) {
cell.finishedHeight = COMMITING_CREATE_CELL_HEIGHT;
if (cell.frame.size.height >= COMMITING_CREATE_CELL_HEIGHT) {
cell.textLabel.text = @"Release to create cell...";
cell.contentView.backgroundColor = cell.tintColor;
} else {
cell.textLabel.text = ADDING_CELL;
cell.contentView.backgroundColor = [UIColor clearColor];
}
cell.detailTextLabel.text = @" ";
} else {
cell.finishedHeight = NORMAL_CELL_FINISHING_HEIGHT;
cell.textLabel.text = [NSString stringWithFormat:@"%@", (NSString *)object];
cell.detailTextLabel.text = @" ";
}


return cell;
}
Expand Down

0 comments on commit 97f80bc

Please sign in to comment.