Lines drawn with core graphics that are set to the

2019-09-06 18:03发布

Here is a picture of two lines drawn in a UITableViewCell with the same function, and same width, and color enter image description here

As you can see the bottom line is a lot thicker than the other line.

The code I am using for drawing:

    [CSDrawing drawLineWithColor:[UIColor blackColor] width:1.0 yPosition:1.0 rect:rect];
    [CSDrawing drawLineWithColor:[UIColor blackColor] width:1.0 yPosition:CGRectGetMaxY(rect) - 3.0 rect:rect]; // draw a line on top and bottom

    +(void)drawLineWithColor:(UIColor *)color width:(CGFloat)width yPosition:(CGFloat)yPosition rect:(CGRect)rect {

          CGContextRef context = UIGraphicsGetCurrentContext();
          CGContextSaveGState(context);

          CGContextMoveToPoint(context, 0.0, yPosition);
          CGContextAddLineToPoint(context, CGRectGetMaxX(rect), yPosition);

          CGContextSetStrokeColorWithColor(context, color.CGColor);
          CGContextSetLineWidth(context, width);

          CGContextStrokePath(context);

          CGContextRestoreGState(context);
     }

1条回答
Ridiculous、
2楼-- · 2019-09-06 18:28

The problem was with the backgroundView being stretched to fit the content of the cell when the cell was being reused. When the cell was bigger the pixels were stretched. This is solved be setting the contentMode property to UIViewContentModeRedraw

查看更多
登录 后发表回答