Lines drawn with core graphics that are set to the same width sometimes vary in size when drawn

旧城冷巷雨未停 提交于 2020-01-25 10:23:19

问题


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

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:


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



来源:https://stackoverflow.com/questions/13539382/lines-drawn-with-core-graphics-that-are-set-to-the-same-width-sometimes-vary-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!