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
.
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]];
proprietà Additionall si possono trovare oltre a documentazione del sull'argomento https://developer.apple.com/.../CAShapeLayer_class/index.html.
fonte
2015-02-10 21:49:50
Come è possibile aumentare la dimensione del bordo/tratto rosso sopra? –
@RohanSanap è possibile farlo modificando la proprietà lineWidth del layer – sbru