Skip to content

Instantly share code, notes, and snippets.

@typeoneerror
Created August 12, 2011 00:07
Show Gist options
  • Select an option

  • Save typeoneerror/1141124 to your computer and use it in GitHub Desktop.

Select an option

Save typeoneerror/1141124 to your computer and use it in GitHub Desktop.
Adjusting size of rect before Quartz drawing to avoid jaggy round-rect and circle strokes
- (void)drawRect:(CGRect)rect
{
// line weight
CGFloat strokeWidth = 2.0f
// adjust size of the canvas to get rid of nasty jaggies
rect.size.width -= strokeWidth;
rect.size.height -= strokeWidth;
rect.origin.x += strokeWidth / 2.0;
rect.origin.y += strokeWidth / 2.0;
// set up drawing
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetShouldAntialias(context, YES);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, strokeWidth);
CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
// draw the fill
CGContextFillEllipseInRect(context, rect);
CGContextStrokeEllipseInRect(context, rect);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment