Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing circle without fill IOS

Tags:

xcode

ios

I am using this code to draw a circle inside a UIImageView.

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];

I would like the circle to be empty, and to have only the border. How can I remove the fill?

like image 400
user2014474 Avatar asked Feb 26 '13 20:02

user2014474


1 Answers

Set the fill color to transparent (alpha 0)

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

AKA...

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

(thanks Zev)

like image 61
foundry Avatar answered Oct 05 '22 08:10

foundry