Skip to content

Instantly share code, notes, and snippets.

@Gurpartap
Created January 17, 2012 08:52
Show Gist options
  • Save Gurpartap/1625722 to your computer and use it in GitHub Desktop.
Save Gurpartap/1625722 to your computer and use it in GitHub Desktop.
Custom abtableviewcell
#import <UIKit/UIKit.h>
#import "ABTableViewCell.h"
@interface MediaTableViewCell : ABTableViewCell
@end
@implementation MediaTableViewCell
static UIImage *backgroundImage = nil;
static UIImage *backgroundImageHighlighted = nil;
+ (void)initialize {
if (self == [MediaTableViewCell class]) {
descriptionFont = [[UIFont systemFontOfSize:20] retain];
badgeTextFont = [[UIFont boldSystemFontOfSize:20] retain];
backgroundImage = [[UIImage imageNamed:@"buddyCellBackground.png"] retain];
backgroundImageHighlighted = [[UIImage imageNamed:@"buddyCellBackgroundSelected.png"] retain];
}
}
+ (void)initBackgroundImages {
if (backgroundImage == nil) {
backgroundImage = [[UIImage imageNamed:@"buddyCellBackground.png"] retain];
}
if (backgroundImageHighlighted == nil) {
backgroundImageHighlighted = [[UIImage imageNamed:@"buddyCellBackgroundSelected.png"] retain];
}
}
- (void)drawContentView:(CGRect)rect highlighted:(BOOL)highlighted {
[MediaTableViewCell initBackgroundImages];
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor whiteColor] set];
CGContextFillRect(context, rect);
if (highlighted || self.isHighlighted || self.isSelected) {
CGSize bgSize = backgroundImageHighlighted.size;
[backgroundImageHighlighted drawInRect:CGRectMake(0, 0, bgSize.width, bgSize.height)];
}
else {
CGSize bgSize = backgroundImage.size;
[backgroundImage drawInRect:CGRectMake(0, 0, bgSize.width, bgSize.height)];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment