Skip to content

Instantly share code, notes, and snippets.

@aaronbrethorst
Created May 16, 2011 00:33
Show Gist options
  • Save aaronbrethorst/973722 to your computer and use it in GitHub Desktop.
Save aaronbrethorst/973722 to your computer and use it in GitHub Desktop.
diff --git a/Classes/MenuViewController.m b/Classes/MenuViewController.m
index 9c36a45..16bc15b 100755
--- a/Classes/MenuViewController.m
+++ b/Classes/MenuViewController.m
@@ -11,6 +11,7 @@
#import "StackScrollViewAppDelegate.h"
#import "RootViewController.h"
#import "StackScrollViewController.h"
+#import "MenuTableViewCell.h"
#define kCellText @"CellText"
#define kCellImage @"CellImage"
@@ -34,11 +35,11 @@
[_cellContents addObject:[NSDictionary dictionaryWithObjectsAndKeys:[UIImage imageNamed:@"06-magnify.png"], kCellImage, NSLocalizedString(@"Search",@""), kCellText, nil]];
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
- [_tableView setDelegate:self];
- [_tableView setDataSource:self];
- [_tableView setBackgroundColor:[UIColor clearColor]];
- _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
- [self.view addSubview:_tableView];
+ _tableView.delegate = self;
+ _tableView.dataSource = self;
+ _tableView.backgroundColor = [UIColor clearColor];
+ _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ [self.view addSubview:_tableView];
}
return self;
}
@@ -87,16 +88,15 @@
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ MenuTableViewCell *cell = (MenuTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
- cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
- UIView* bgView = [[[UIView alloc] init] autorelease];
- [bgView setBackgroundColor:[UIColor colorWithWhite:2 alpha:0.2]];
- [cell setSelectedBackgroundView:bgView];
+ cell = [[[MenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [[_cellContents objectAtIndex:indexPath.row] objectForKey:kCellText];
cell.imageView.image = [[_cellContents objectAtIndex:indexPath.row] objectForKey:kCellImage];
+
+ cell.glowView.hidden = indexPath.row != 3;
return cell;
}
- (id)initWithFrame:(CGRect)aRect
{
if ((self = [super initWithFrame:aRect]))
{
UIView* topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 1)];
topLine.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.25];
[self addSubview:topLine];
[topLine release];
UIImageView *watermark = [[UIImageView alloc] initWithFrame:CGRectMake(0, 1, 200, 79)];
watermark.contentMode = UIViewContentModeCenter;
watermark.image = [UIImage imageNamed:@"watermark.png"];
[self addSubview:watermark];
[watermark release];
}
return self;
}
diff --git a/Classes/MenuViewController.m b/Classes/MenuViewController.m
index 1ac2a71..84a2e89 100755
--- a/Classes/MenuViewController.m
+++ b/Classes/MenuViewController.m
@@ -13,6 +13,7 @@
#import "StackScrollViewController.h"
#import "MenuTableViewCell.h"
#import "MenuHeaderView.h"
+#import "MenuWatermarkFooter.h"
#define kCellText @"CellText"
#define kCellImage @"CellImage"
@@ -44,6 +45,7 @@
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
+ _tableView.tableFooterView = [[[MenuWatermarkFooter alloc] initWithFrame:CGRectMake(0, 0, 200, 80)]
[self.view addSubview:_tableView];
}
return self;
+ (int)heightForTweetWithText:(NSString*)tweetText
{
CGFloat height = 0;
height += 12; // top padding.
height += 18; // author label.
height += 5; // padding between author and tweet.
CGSize tweetTextSize = [tweetText sizeWithFont:[UIFont boldSystemFontOfSize:[UIFont labelFontSize]] constrainedToSize:CGSizeMake(390, 10000) lineBreakMode:UILineBreakModeWordWrap];
height += tweetTextSize.height;
height += 12; // bottom padding.
return (int)height;
}
diff --git a/Classes/DataViewController.h b/Classes/DataViewController.h
index 0cce20f..756889c 100755
--- a/Classes/DataViewController.h
+++ b/Classes/DataViewController.h
@@ -14,6 +14,7 @@
RoundedUITableView* _tableView;
NSArray *tweets;
+ NSDateFormatter *formatter;
}
- (id)initWithFrame:(CGRect)frame squareCorners:(BOOL)squareCorners;
diff --git a/Classes/DataViewController.m b/Classes/DataViewController.m
index c60be8f..cb71089 100755
--- a/Classes/DataViewController.m
+++ b/Classes/DataViewController.m
@@ -12,6 +12,7 @@
#import "StackScrollViewController.h"
#import "RoundedUITableView.h"
#import "TweetTableViewCell.h"
+#import "NSDate+Formatting.h"
@implementation DataViewController
@synthesize tableView = _tableView;
@@ -25,6 +26,17 @@
{
tweets = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tweets" of
+ //http://stackoverflow.com/questions/2002544/iphone-twitter-api-converting-time
+ formatter = [[NSDateFormatter alloc] init];
+ NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
+ [formatter setLocale:usLocale];
+ [usLocale release];
+ [formatter setDateStyle:NSDateFormatterLongStyle];
+ [formatter setFormatterBehavior:NSDateFormatterBehavior10_4];
+
+ // see http://unicode.org/reports/tr35/tr35-6.html#Date_Format_Patterns
+ [formatter setDateFormat: @"EEE MMM dd HH:mm:ss +0000 yyyy"];
+
[self.view setFrame:frame];
_tableView = [[RoundedUITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,
@@ -87,11 +99,14 @@
}
NSDictionary *tweet = [tweets objectAtIndex:indexPath.row];
-
+
+ NSDate *createdAt = [formatter dateFromString:[tweet objectForKey:@"created_at"]];
+
cell.imageView.image = [UIImage imageNamed:@"avatar.png"];
cell.authorLabel.text = [[tweet objectForKey:@"user"] objectForKey:@"screen_name"];
cell.tweetLabel.text = [tweet objectForKey:@"text"];
-
+ cell.timestampLabel.text = [createdAt distanceOfTimeInWords];
+
return cell;
}
@@ -117,6 +132,7 @@
- (void)dealloc {
+ [formatter release];
[tweets release];
[super dealloc];
}
- (id)initWithFrame:(CGRect)aFrame
{
if ((self = [super initWithFrame:aFrame]))
{
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(11, 11, 48, 48)];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.layer.cornerRadius = 3.f;
imageView.layer.masksToBounds = YES;
imageView.layer.shadowColor = [[UIColor blackColor] CGColor];
imageView.layer.shadowOffset = CGSizeMake(0, 3);
imageView.layer.shadowOpacity = 0.5f;
imageView.layer.shadowRadius = 3.0f;
imageView.layer.shouldRasterize = YES;
[self addSubview:imageView];
textLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 11, 119, 48)];
textLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
textLabel.textColor = [UIColor colorWithRed:(188.f/255.f) green:(188.f/255.f) blue:(188.f/255.f) alpha:1.f];
textLabel.shadowOffset = CGSizeMake(0, 2);
textLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.25];
textLabel.backgroundColor = [UIColor clearColor];
[self addSubview:textLabel];
}
return self;
}
#import "MenuTableViewCell.h"
@implementation MenuTableViewCell
@synthesize glowView;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]))
{
self.clipsToBounds = YES;
UIView* bgView = [[UIView alloc] init];
bgView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.25f];
self.selectedBackgroundView = bgView;
[bgView release];
self.textLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
self.textLabel.shadowOffset = CGSizeMake(0, 2);
self.textLabel.shadowColor = [UIColor colorWithWhite:0 alpha:0.25];
self.imageView.contentMode = UIViewContentModeCenter;
UIView *topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 1)];
topLine.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.25];
[self.textLabel.superview addSubview:topLine];
[topLine release];
UIView *bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 200, 1)];
bottomLine.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];
[self.textLabel.superview addSubview:bottomLine];
[bottomLine release];
glowView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 43)];
glowView.image = [UIImage imageNamed:@"glow.png"];
glowView.hidden = YES;
[self addSubview:glowView];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.textLabel.frame = CGRectMake(75, 0, 125, 43);
self.imageView.frame = CGRectMake(0, 0, 70, 43);
}
- (void)setSelected:(BOOL)sel animated:(BOOL)animated
{
[super setSelected:sel animated:animated];
if (sel)
{
self.textLabel.textColor = [UIColor whiteColor];
}
else
{
self.textLabel.textColor = [UIColor colorWithRed:(188.f/255.f) green:(188.f/255.f) blue:(188.f/255.f) alpha:1.f];
}
}
- (void)dealloc
{
[glowView release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment