Tarek, thanks. Another minor thing. If the cell selectionStyle is equal to UITableViewCellEditingStyleNone I think the badge view shouldn't be painted white. Here's I'm checking for the selectionStyle:
- (void)drawRect:(CGRect)rect
{
if(!self.text)
return;
UIColor *badgeColor = self.color;
UIView *spview = self.superview;
while (spview)
{
if([spview isKindOfClass:[UITableViewCell class]])
{
UITableViewCell *ownerCell = (UITableViewCell *)spview;
if((ownerCell.highlighted || ownerCell.selected) && ownerCell.selectionStyle != UITableViewCellEditingStyleNone)
badgeColor = [UIColor whiteColor];
break;
}
spview = spview.superview;
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, [badgeColor CGColor]);
CGContextBeginPath(context);
CGFloat radius = self.bounds.size.height / 2.0;
CGContextAddArc(context, radius, radius, radius, M_PI/2 , 3*M_PI/2, NO);
CGContextAddArc(context, self.bounds.size.width - radius, radius, radius, 3*M_PI/2, M_PI/2, NO);
CGContextClosePath(context);
CGContextFillPath(context);
CGContextRestoreGState(context);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGSize textSize = CGSizeMake(0, 0);
if(self.text)
textSize = [self.text sizeWithFont:self.font];
CGRect textBounds = CGRectMake(round((self.bounds.size.width-textSize.width)/2),
round((self.bounds.size.height-textSize.height)/2),
textSize.width, textSize.height);
[self.text drawInRect:textBounds withFont:self.font];
}
The change is this:
if((ownerCell.highlighted || ownerCell.selected) && ownerCell.selectionStyle != UITableViewCellEditingStyleNone)