Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - Set dashed line for a circle

Tags:

ios

line

CAShapeLayer *circle = [CAShapeLayer layer];

circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath;

// Configure the apperence of the circle
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor whiteColor].CGColor;
circle.lineWidth = 1;      
// Add to parent layer
[[background layer] addSublayer:circle];

I have drawn a circle and added it as a sublayer. What I don't understand is how to make the circle line dashed? I have added my circle code above.

like image 456
spacecash21 Avatar asked Oct 19 '12 18:10

spacecash21


1 Answers

You need to set the lineDashPattern property of circle. For example:

circle.lineDashPattern = @[@2, @3];
like image 52
rob mayoff Avatar answered Oct 05 '22 03:10

rob mayoff