Strange problem with line drawing on iPad
I have a task to draw a separator line with 2px height between UIView cells. Top 1px high line should have color #F1F1F1 and bottom 1px high line should have color #DDDDDD As result, on iPhone simulator with Retina display these 2 lines are seen clearly with different colors (#F1F1F1 and #DDDDDD parts), on iPad simulator - line is distorted, and there are no lines with such colors.
Code fragment used for drawing such line:
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextSetLineWidth(context, 1.);
CGContextSetStrokeColor(context, CGColorGetComponents(
[[GlobalHelper colorFromHexRGB:@"#F1F1F1"] CGColor]) );
CGContextMoveToPoint(context, 0., line_y);
CGContextAddLineToPoint(context, rect.size.width, line_y );
CGContextStrokePath(context);
CGContextRestoreGState(context);
CGContextSaveGState(context);
CGContextSetLineWidth(context, 1.);
CGContextSetStrokeColor(context,
CGColorGetComponents([[GlobalHelper colorFromHexRGB:@"#DDDDDD"] CGColor]));
line_y += 1.;
CGContextMoveToPoint(context, 0., li开发者_如何学编程ne_y);
CGContextAddLineToPoint(context, rect.size.width, line_y );
CGContextStrokePath(context);
CGContextRestoreGState(context);
For view object, which used as holder for drawing line (this is subclass of UITableViewCell). I tried changing parameters "opaque" and "clearsContextBeforeDrawing". Same result - on iPhone Retina all OK, for iPad - line is distorted.
Any ideas on what is causing this and how to fix it?
One idea: a 1-pixel wide line drawn at an integral coordinate will be blurred because half of the line will be on each side of the pixel boundary. Try adding 0.5 to your line_y
coordinate and see if it fixes your problem.
精彩评论