Skip to content

Commit

Permalink
Subclassing UITableViewCell
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbrethorst committed May 16, 2011
1 parent 83b8891 commit 687560b
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 10 deletions.
16 changes: 16 additions & 0 deletions Classes/MenuTableViewCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// MenuTableViewCell.h
// StackScrollView
//
// Created by Aaron Brethorst on 5/15/11.
// Copyright 2011 Structlab LLC. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface MenuTableViewCell : UITableViewCell
{
UIImageView *glowView;
}
@property(nonatomic,retain) UIImageView *glowView;
@end
76 changes: 76 additions & 0 deletions Classes/MenuTableViewCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// MenuTableViewCell.m
// StackScrollView
//
// Created by Aaron Brethorst on 5/15/11.
// Copyright 2011 Structlab LLC. All rights reserved.
//

#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
20 changes: 10 additions & 10 deletions Classes/MenuViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "StackScrollViewAppDelegate.h"
#import "RootViewController.h"
#import "StackScrollViewController.h"
#import "MenuTableViewCell.h"

#define kCellText @"CellText"
#define kCellImage @"CellImage"
Expand All @@ -34,11 +35,11 @@ - (id)initWithFrame:(CGRect)frame {
[_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;
}
Expand Down Expand Up @@ -87,16 +88,15 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
- (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;
}
Expand Down
10 changes: 10 additions & 0 deletions StackScrollView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
93D1BA71138098FF0094D5A5 /* 111-user.png in Resources */ = {isa = PBXBuildFile; fileRef = 93D1BA6B138098FF0094D5A5 /* 111-user.png */; };
93D1BA72138098FF0094D5A5 /* 18-envelope.png in Resources */ = {isa = PBXBuildFile; fileRef = 93D1BA6C138098FF0094D5A5 /* 18-envelope.png */; };
93D1BA73138098FF0094D5A5 /* 22-skull-n-bones.png in Resources */ = {isa = PBXBuildFile; fileRef = 93D1BA6D138098FF0094D5A5 /* 22-skull-n-bones.png */; };
93D1BA8513809B570094D5A5 /* MenuTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 93D1BA8413809B570094D5A5 /* MenuTableViewCell.m */; };
93D1BAD313809E780094D5A5 /* glow.png in Resources */ = {isa = PBXBuildFile; fileRef = 93D1BAD213809E780094D5A5 /* glow.png */; };
C12A8A50131776B500E7CA88 /* UIViewWithShadow.m in Sources */ = {isa = PBXBuildFile; fileRef = C12A8A4F131776B500E7CA88 /* UIViewWithShadow.m */; };
C1842AEF1316641600D1538C /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C1842AEE1316641600D1538C /* RootViewController.m */; };
C1842AF9131664DD00D1538C /* MenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C1842AF8131664DD00D1538C /* MenuViewController.m */; };
Expand Down Expand Up @@ -48,6 +50,9 @@
93D1BA6C138098FF0094D5A5 /* 18-envelope.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "18-envelope.png"; sourceTree = "<group>"; };
93D1BA6D138098FF0094D5A5 /* 22-skull-n-bones.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "22-skull-n-bones.png"; sourceTree = "<group>"; };
93D1BA6E138098FF0094D5A5 /* Icons from Glyphish.webloc */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; path = "Icons from Glyphish.webloc"; sourceTree = "<group>"; };
93D1BA8313809B570094D5A5 /* MenuTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MenuTableViewCell.h; sourceTree = "<group>"; };
93D1BA8413809B570094D5A5 /* MenuTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MenuTableViewCell.m; sourceTree = "<group>"; };
93D1BAD213809E780094D5A5 /* glow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = glow.png; sourceTree = "<group>"; };
C12A8A4E131776B500E7CA88 /* UIViewWithShadow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIViewWithShadow.h; sourceTree = "<group>"; };
C12A8A4F131776B500E7CA88 /* UIViewWithShadow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIViewWithShadow.m; sourceTree = "<group>"; };
C1842AED1316641600D1538C /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,6 +97,8 @@
2752544313790ADD005E9019 /* StackScrollViewController.m */,
93D1B7DB1380626C0094D5A5 /* RoundedUITableView.h */,
93D1B7DC1380626C0094D5A5 /* RoundedUITableView.m */,
93D1BA8313809B570094D5A5 /* MenuTableViewCell.h */,
93D1BA8413809B570094D5A5 /* MenuTableViewCell.m */,
);
path = Classes;
sourceTree = "<group>";
Expand Down Expand Up @@ -129,6 +136,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
93D1BAD213809E780094D5A5 /* glow.png */,
C1D438961317D30A00D5EE69 /* backgroundImage_repeat.png */,
28AD733E0D9D9553002E5188 /* MainWindow.xib */,
8D1107310486CEB800E47090 /* StackScrollView-Info.plist */,
Expand Down Expand Up @@ -225,6 +233,7 @@
93D1BA71138098FF0094D5A5 /* 111-user.png in Resources */,
93D1BA72138098FF0094D5A5 /* 18-envelope.png in Resources */,
93D1BA73138098FF0094D5A5 /* 22-skull-n-bones.png in Resources */,
93D1BAD313809E780094D5A5 /* glow.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -243,6 +252,7 @@
C12A8A50131776B500E7CA88 /* UIViewWithShadow.m in Sources */,
2752544413790ADD005E9019 /* StackScrollViewController.m in Sources */,
93D1B7DD1380626C0094D5A5 /* RoundedUITableView.m in Sources */,
93D1BA8513809B570094D5A5 /* MenuTableViewCell.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file added glow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 687560b

Please sign in to comment.