CGContext - Drawing Circle
CGContext - Drawing Circle
- Subject: CGContext - Drawing Circle
- From: Dave <email@hidden>
- Date: Thu, 04 Jul 2013 12:44:12 +0100
Hi,
I have a custom class, subclassed from UIControl that draws a circle with an X in it (like a circular check box control). This works ok, but the circle looks scrappy when displayed on the iPad. The method that does the work is appended to this mail and is called from the drawRect method of the class.
Is there something I am doing wrong? It really doesn't look like a nice circle!
Thanks in advance,
Dave
- (void) drawCheckBoxStyleCircle:(CGRect) theDrawRect
{
CGContextRef myGraphicsContext;
CGFloat myStrokeColor[4] = {0,0,0,1};
CGFloat myFillColor[4] = {255,255,255,1};
CGColorSpaceRef myColorspaceRef;
CGFloat myCenterXPosition;
CGFloat myCenterYPosition;
CGFloat myRadius;
CGRect myInnerRect;
myGraphicsContext = UIGraphicsGetCurrentContext();
CGContextSetStrokeColor(myGraphicsContext,myStrokeColor);
CGContextSetFillColor(myGraphicsContext,myFillColor);
myColorspaceRef = CGColorSpaceCreateDeviceRGB();
myCenterXPosition = theDrawRect.origin.x + (theDrawRect.size.width / 2);
myCenterYPosition = theDrawRect.origin.y + (theDrawRect.size.height / 2);
myRadius = theDrawRect.size.width / 2;
CGContextSetLineWidth(myGraphicsContext,2);
CGContextAddArc(myGraphicsContext,myCenterXPosition,myCenterYPosition,myRadius,0,2 * M_PI,1);
CGContextStrokePath(myGraphicsContext);
if (self.pCheckBoxSelectedFlag == YES)
{
myInnerRect = CGRectMake(CGRectGetMinX(theDrawRect) + 6,CGRectGetMinY(theDrawRect) + 6,CGRectGetWidth(theDrawRect) - 12,CGRectGetHeight(theDrawRect) - 12);
CGContextSetLineWidth(myGraphicsContext,3);
CGContextBeginPath(myGraphicsContext);
CGContextMoveToPoint(myGraphicsContext,CGRectGetMinX(myInnerRect),CGRectGetMinY(myInnerRect));
CGContextAddLineToPoint(myGraphicsContext,CGRectGetMaxX(myInnerRect),CGRectGetMaxY(myInnerRect));
CGContextStrokePath(myGraphicsContext);
CGContextMoveToPoint(myGraphicsContext,CGRectGetMinX(myInnerRect),CGRectGetMaxY(myInnerRect));
CGContextAddLineToPoint(myGraphicsContext,CGRectGetMaxX(myInnerRect),CGRectGetMinY(myInnerRect));
CGContextStrokePath(myGraphicsContext);
}
}
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden