I need to customize the cells of a table creating two transparent strips, one in correspondence of the upper edge of UITableViewCell, and other in correspondence of the lower edge. These strips should be transparent to see the color of the view below (light yellow).
I created a subclass of UITableViewCell and I built the method LayoutSubviews() to draw the strips, it is wrong? I get this errors:
<Error>: CGContextBeginPath: invalid context 0x0
<Error>: CGContextMoveToPoint: invalid context 0x0
<Error>: CGContextAddLineToPoint: invalid context 0x0
<Error>: CGContextSetLineWidth: invalid context 0x0
<Error>: CGContextSetFillColorWithColor: invalid context 0x0
<Error>: CGContextMoveToPoint: invalid context 0x0
<Error>: CGContextAddLineToPoint: invalid context 0x0
<Error>: CGContextSetLineWidth: invalid context 0x0
<Error>: CGContextSetFillColorWithColor: invalid context 0x0
This is the code in CustomCell.m:
-(void) layoutSubviews{
[super layoutSubviews];
CGContextRef ctxt = UIGraphicsGetCurrentContext();
CGContextBeginPath(ctxt);
CGContextMoveToPoint(ctxt, self.bounds.origin.x, self.bounds.origin.y);
CGContextAddLineToPoint(ctxt, self.bounds.size.width, self.bounds.origin.y);
CGContextSetLineWidth(ctxt, 5);
CGContextSetFillColorWithColor(ctxt, [UIColor clearColor].CGColor);
CGContextMoveToPoint(ctxt, self.bounds.origin.x, self.bounds.size.height);
CGContextAddLineToPoint(ctxt, self.bounds.size.width, self.bounds.size.height);
CGContextSetLineWidth(ctxt, 5);
CGContextSetFillColorWithColor(ctxt, [UIColor clearColor].CGColor);
CGContextStrokePath(ctxt);
}
layoutSubviewsis the wrong method to draw something. You don’t have a drawing context there. Move your code todrawRect::