Created
August 12, 2011 00:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (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