I was able to draw a dashed box, using the following code:
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
CGRect shapeRect = CGRectMake(0.0f, 0.0f, 200.0f,
Swift, more compact:
func addDashedLine(fromPoint start: CGPoint, toPoint end:CGPoint) {
let line = CAShapeLayer()
let linePath = UIBezierPath()
linePath.moveToPoint(start)
linePath.addLineToPoint(end)
line.path = linePath.CGPath
line.strokeColor = UIColor.redColor().CGColor
line.lineWidth = 1
line.lineJoin = kCALineJoinRound
line.lineDashPattern = [4, 4]
self.layer.addSublayer(line)
}
CAShapeLayer *shaplayer = [CAShapeLayer layer];
shaplayer.frame = CGRectMake(100, 100, 100, 100);
[self.view.layer addSublayer:shaplayer];
UIBezierPath *uipath = [UIBezierPath bezierPath];
[uipath moveToPoint:CGPointMake(50, 200)];
[uipath addLineToPoint:CGPointMake(250, 200)];
shaplayer.path = uipath.CGPath;
shaplayer.strokeColor = [UIColor redColor].CGColor;
shaplayer.lineDashPattern = @[@4];