2013-02-26 13 views
12

Sto usando questo codice per disegnare un cerchio all'interno di un UIImageView.Disegno cerchio senza riempimento IOS

CAShapeLayer *circleLayer = [CAShapeLayer layer]; 
// Give the layer the same bounds as your image view 
[circleLayer setBounds:CGRectMake(0.0f, 0.0f, [photoView bounds].size.width, 
            [photoView bounds].size.height)]; 
// Position the circle anywhere you like, but this will center it 
// In the parent layer, which will be your image view's root layer 
[circleLayer setPosition:CGPointMake(coordsFinal.x + 130, coordsFinal.y + 200)]; 
// Create a circle path. 
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect: 
         CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)]; 
// Set the path on the layer 
[circleLayer setPath:[path CGPath]]; 
// Set the stroke color 
[circleLayer setStrokeColor:[color CGColor]]; 
// Set the stroke line width 
[circleLayer setLineWidth:2.0f]; 

// Add the sublayer to the image view's layer tree 
[[photoView layer] addSublayer:circleLayer]; 

Vorrei che il cerchio fosse vuoto e che avesse solo il bordo. Come posso rimuovere il riempimento?

risposta

18

impostare il colore di riempimento a trasparente (alfa 0)

[circleLayer setFillColor:[[UIColor colorWithWhite:0 alpha:0] CGColor]]; 

AKA ...

[circleLayer setFillColor:[[UIColor clearColor] CGColor]]; 

(grazie Zev)

+4

o '[[UIColor clearColor] CGColor]'. –

+1

anzi ... stavo per aggiornare! – foundry

3

La pagina di manuale di CAShapeLayer esplicitamente dice set fillColor a nil per eseguire nessuna operazione di riempimento. Non è lo stesso che riempire con un colore trasparente, che alcuni hanno suggerito di fare, dato che quest'ultimo sovrascriverà i contenuti esistenti rendendoli chiari/trasparenti e dovrebbe essere considerato un'operazione distruttiva.

Problemi correlati