开发者社区> 问答> 正文

关于在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;

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

展开
收起
爵霸 2016-03-23 11:21:37 1670 0
1 条回答
写回答
取消 提交回答
  • 我觉得是 backgroundView 的大小 正好 覆盖了 你划的线 看代码 你的线 应该是在边界的位置吧

    2019-07-17 19:10:36
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载