Core Graphics, gewusst wie: zeichnen Sie ein Rechteck mit einer ellipse Transparenz Loch?

Ich versuche zu zeichnen, 320x480 Rechtecks, das ausgehöhlte durch eine ellipse.
Vorstellen, zeichnen Sie ein gefülltes Rechteck, über das Rechteck eine gefüllte ellipse, und entfernen Sie die ellipse aus dem Rechteck, so dass eine transparente Loch.

- (void)drawRect:(CGRect)rect
{
        //Drawing code.
    CGContextRef context = UIGraphicsGetCurrentContext();
    //Set color to red
    CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1.0);
    //Add rectange
    CGContextAddRect(context, rect);
    //Fill rectange
    CGContextFillRect(context, rect);

    //Create a elipse to be removed from rectange

    CGPathRef circlePath = CGPathCreateMutable();       
    CGPathAddEllipseInRect(circlePath , NULL , elipseRect);

    CGContextAddPath(context, circlePath);  
    CGContextSetRGBFillColor(context, 1.0, 1.0, 0.0, 1.0);
    CGContextFillPath(context);

    //clip elipse... (DO NOT WORK)
    CGContextEOClip(context);
}

Wenn ich versuche mich zu entfernen, die elipse aus der rectange, funktioniert es nicht.

Jemand eine Lösung hat?

InformationsquelleAutor Jan | 2011-07-29
Schreibe einen Kommentar