Skip to content

Instantly share code, notes, and snippets.

@jonsterling
Created March 28, 2010 20:56
Show Gist options
  • Save jonsterling/347039 to your computer and use it in GitHub Desktop.
Save jonsterling/347039 to your computer and use it in GitHub Desktop.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
CGRect r1 = CGRectMake(0.0f, 0.0f, tableView.frame.size.width,
[self tableView:tableView heightForHeaderInSection:section]);
CGRect r2 = r1;
r2.size.height += 15.0f;
UIView *v = [[UIView alloc] initWithFrame:r1];
SectionHeaderView *shv = [[SectionHeaderView alloc] initWithFrame:r2];
[shv setTitle:[self tableView:tableView titleForHeaderInSection:section]];
[v addSubview:shv];
[shv release];
return [v autorelease];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 30.0f;
}
#import <UIKit/UIKit.h>
@interface SectionHeaderView : UIView {
NSString *_title;
}
@property (nonatomic, copy) NSString *title;
@end
#import "SectionHeaderView.h"
static UIImage *_ribbonImage = nil;
@implementation SectionHeaderView
@synthesize title = _title;
+ (void)initialize {
_ribbonImage = [[UIImage imageNamed:@"Ribbon.png"] retain];
}
- initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
[self setBackgroundColor:[UIColor clearColor]];
} return self;
}
- (void)setTitle:(NSString *)aTitle {
[_title autorelease];
_title = [aTitle copy];
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
[_ribbonImage drawInRect:rect];
UILabel *label = [[UILabel alloc] initWithFrame:rect];
[label setFont:[UIFont boldSystemFontOfSize:18]];
[label setTextColor:[UIColor whiteColor]];
[label setShadowColor:[UIColor colorWithWhite:0.0f alpha:1.0f]];
[label setShadowOffset:CGSizeMake(0.0f, 1.0f)];
[label setTextAlignment:UITextAlignmentCenter];
[label setText:self.title];
[label drawTextInRect:rect];
[label release];
}
- (void)dealloc {
[_title release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment