1

I have a collectionviewcell cell and I am adding a CAShapeLayer to give my frontImageView a half border. The code I have now successfully creates a half border but not where I want it. Setting stokeEnd=0.5 creates a half border on the bottom of my imageView. I would like the border to be on the right side of the imageView. From the top center to bottom center (right side).

Can I draw the stroke line from the top center of my imageView to the bottom center, along the right side?

CAShapeLayer *shape = [CAShapeLayer layer];
UIBezierPath *path=[UIBezierPath bezierPathWithOvalInRect:cell.frontImageView.frame];
[shape setPath:path.CGPath];

shape.strokeColor=[UIColor purpleColor].CGColor;
shape.fillColor=[UIColor clearColor].CGColor;
shape.lineWidth = 5.0f;
shape.lineCap = kCALineCapRound;
[shape setStrokeEnd:0.5];
[cell.layer addSublayer:shape];
Peter
  • 1,053
  • 13
  • 29

1 Answers1

0

You can create a path by using a general arc path: (Swift 4.2)

UIBezierPath(arcCenter: view.center, radius: view.frame.width / 2, startAngle: -CGFloat.pi / 2.0, endAngle: CGFloat.pi / 2.0, clockwise: true)

Set your shape's path by this path.

Tony Nguyen
  • 491
  • 3
  • 7