Tuesday, 21 January 2014

Create a circle programmatically

Create a New view then add this code:

- (void)drawRect:(CGRect)rect {
    if (canDraw == YES) {
        // The color is by this line CGContextSetRGBFillColor( context , red , green , blue , alpha);
        CGContextRef contextRef = UIGraphicsGetCurrentContext();
        // Draw a circle (filled)
        CGContextFillEllipseInRect(contextRef, CGRectMake(100, 100, 25, 25));
        CGContextSetRGBFillColor(contextRef, 0, 0, 255, 1.0);
        
        // Draw a circle (border only)
        CGContextStrokeEllipseInRect(contextRef, CGRectMake(100, 200, 25, 25));
        CGContextSetRGBFillColor(contextRef, 0, 0, 255, 1.0); 
    }

}

No comments:

Post a Comment