PDA

View Full Version : Drawing in a custom UITableViewCell




Turias
Jan 1, 2009, 07:17 PM
Hello,

I am trying to draw in a custom UITableViewCell, but I can apparently only draw outside the white rounded rectangle that usually defines the cell. Anything I try to draw within that space seems to go behind the white shape. Take the following code, for example:


- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];

CGRect drawRect = CGRectMake(rect.origin.x + 2, rect.origin.y + 2, rect.size.width - 4, rect.size.height - 4);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(context, 0.2, 0.5, 0.2, 0.8);
CGContextFillRect(context, drawRect);
}


In this case, I can see my green rectangle to the left and to the right of the normal cell, but the white cell itself seems untouched (see the attached image).

What am I doing wrong? How can I draw within my custom cell? Any help would be greatly appreciated. Thanks!



Turias
Jan 1, 2009, 08:11 PM
Actually, I think it's because I need to get the UIButton object out of the UITableViewCell and draw in that. Doh! Too much coding, today...