在UITableViewcell中划线

drawRect代码如下:

-(void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    CGContextRef cxt = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(cxt, 2.0);
    CGContextSetStrokeColorWithColor(cxt, [UIColor redColor].CGColor);
    CGContextMoveToPoint(cxt, 250.0 , 0.0);
    CGContextAddLineToPoint(cxt, 250.0, 50.0);
   CGContextStrokePath(cxt);
}

会画出红色的线。但是一设置cell的背景线就会消失。设置背景的代码:

UIView *view = [[UIView alloc] initWithFrame:cell.frame];
        view.backgroundColor = [UIColor grayColor];
    cell.backgroundView = view;

怎么回事?为什么背景会隐藏起来红线呢?谢谢您的解答。

我觉得是 backgroundView 的大小 正好 覆盖了 你划的线 看代码 你的线 应该是在边界的位置吧