Created
January 17, 2012 08:52
-
-
Save Gurpartap/1625722 to your computer and use it in GitHub Desktop.
Custom abtableviewcell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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