2015-02-10 21 views

risposta

83

Un modo molto facile e diretto per disegnare un cerchio è creare un CAShapeLayer e aggiungere un UIBezierPath.

CAShapeLayer *circleLayer = [CAShapeLayer layer]; 
[circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 100, 100)] CGPath]]; 

Dopo aver creato la CAShapeLayer abbiamo impostato la sua path essere un UIBezierPath.

Il nostro UIBezierPath quindi disegna un bezierPathWithOvalInRect. Il CGRect che imposterai avrà effetto sulle sue dimensioni e posizione.

Ora che abbiamo la nostra cerchia, possiamo aggiungerla al nostro UIView come sublayer.

[[self.view layer] addSublayer:circleLayer]; 

nostro cerchio è ora visibile nella nostra UIView.

Circle

Se vogliamo personalizzare le proprietà dei colori del nostro circolo si può facilmente farlo impostando stroke s' il CAShapeLayer - e fill colore.

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

Circle_wColors

proprietà Additionall si possono trovare oltre a documentazione del  sull'argomento https://developer.apple.com/.../CAShapeLayer_class/index.html.

+2

Come è possibile aumentare la dimensione del bordo/tratto rosso sopra? –

+0

@RohanSanap è possibile farlo modificando la proprietà lineWidth del layer – sbru

Problemi correlati