views:

115

answers:

2

I just want draw some simples circle on the iPhone, I think it is too complex to using openGL doing this sample job, but I find that the UIB don't have something like canvas, any suggestion on drawing sample images on iPhone? thx a lot.

A: 

Have you tried the iPhone documentation? You're looking for a UIView. The linked documentation gives you a good overview with references to more specific information. There're even code examples on that very page.

Joshua Nozzi
+1  A: 

Create a class that extends UIView and implement the drawRect method:

- (void)drawRect:(CGRect)rect
{
    // Get the graphics context and clear it
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextClearRect(ctx, rect);

    // Draw a red solid square
    CGContextSetRGBFillColor(ctx, 255, 0, 0, 1);
    CGContextFillRect(ctx, CGRectMake(10, 10, 50, 50));

    // Draw a green solid circle
    CGContextSetRGBFillColor(ctx, 0, 255, 0, 1);
    CGContextFillEllipseInRect(ctx, CGRectMake(100, 100, 25, 25));
}
Randy Simon