@interface MyCustomCell : UITableViewCell {
//taking two buttons in every cell.
UIImageView *img;
UILabel *title;
UILabel *subtitle;
}
@end
___________________________________________________________
@implementation MyCustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
forIndexPath:(NSIndexPath *)indexPath inViewController:(UIViewController *)vc {
if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// [self setBackgroundColor:[UIColor clearColor]];
NSString *strTitle = [mc.options objectAtIndex:indexPath.row];
switch(indexPath.row) {
case 0: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"0.png"]];
break;
case 1: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"1.png"]];
break;
case 2: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"2.png"]];
break;
case 3: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"3.png"]];
break;
case 4: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"4.png"]];
break;
case 5: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"5.png"]];
break;
case 6: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"6.png"]];
break;
case 7: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"7.png"]];
break;
case 8: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"8.png"]];
break;
case 9: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"9.png"]];
break;
case 10: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"10.png"]];
break;
case 11: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"11.png"]];
break;
case 12: img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"12.png"]];
break;
}
title = [[UILabel alloc] init];
UIFont *fontTitle = [UIFont fontWithName:@"Georgia" size:16.0];
if(title) {
[title setText:strTitle];
[title setBackgroundColor:[UIColor clearColor]];
title.font = fontTitle;
}
// else {
// [self.textLabel setText:strTitle];
// [self.textLabel setBackgroundColor:[UIColor clearColor]];
// self.textLabel.font = fontTitle;
// }
subtitle=(1 == indexPath.row)?[[UILabel alloc] init]:nil;
if(subtitle) {
[subtitle setBackgroundColor:[UIColor clearColor]];
subtitle.font=[UIFont fontWithName:@"Georgia" size:14.0];
}
[self addSubview:img];
[self addSubview:title];
if(subtitle)
[self addSubview:subtitle];
// [img release];
// [title release];
// [subtitle release];
}
return self;
}
#define celllayoutoffset 5
#define cellgroupoffset 10
- (void)layoutSubviews {
/*
// gradient
CAGradientLayer *gradient = [CAGradientLayer layer];
CGRect rct = self.bounds;
gradient.cornerRadius = 5.0;
gradient.frame = CGRectMake(rct.origin.x + celllayoutoffset, rct.origin.y, rct.size.width - (2 * celllayoutoffset), rct.size.height);
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor], (id)[[UIColor colorWithRed:0 green:0 blue:1 alpha:1.0] CGColor], nil];
[self.layer insertSublayer:gradient atIndex:0];
// gradient end
*/
CGRect rctCell = self.bounds;
int ImgHeightAndWidth = rctCell.size.height - (2 * celllayoutoffset);
CGRect rctImg = CGRectMake(cellgroupoffset + 3, celllayoutoffset, ImgHeightAndWidth, ImgHeightAndWidth);
[img setFrame:rctImg];
if(nil != subtitle) {
CGRect rctTitle = CGRectMake((2 * cellgroupoffset) + rctImg.size.width, 0, rctCell.size.width - (2.5 * ImgHeightAndWidth), rctCell.size.height * 0.5);
CGRect rctSubTitle = CGRectMake((2 * cellgroupoffset) + rctImg.size.width, ImgHeightAndWidth * 0.5, rctCell.size.width - (2.5 * ImgHeightAndWidth), rctCell.size.height * 0.5);
[title setFrame:rctTitle];
[subtitle setFrame:rctSubTitle];
NSDate *now=[NSDate date];
NSDateFormatter *tempdateformat=[[NSDateFormatter alloc] init];
[tempdateformat setDateStyle:kCFDateFormatterLongStyle];
NSString *dateformat=[tempdateformat stringFromDate:now];
[subtitle setText:dateformat];
}
else {
CGRect rctTitle = CGRectMake((2 * cellgroupoffset) + rctImg.size.width, 0, rctCell.size.width - (2.5 * ImgHeightAndWidth), rctCell.size.height);
[title setFrame:rctTitle];
}
}
- (void)dealloc {
[super dealloc];
}
@end