Reputation: 101
I am using UIBezierPath
and CAShapeLayer
to draw a line and adding it inside a view as a sublayer. Everything works fine, Now I have to resize 'Line' with its parent view with strictly keeping the proportion same of line with the view.
Here is the code of creating a line:
let line = UIBezierPath.arrow(from: startPoint, to: endPoint, tailWidth: 5, headWidth: 20, headLength: CGFloat(inputLength * 0.1))
let shapeLayer = CAShapeLayer()
shapeLayer.path = line .cgPath
self.view.layer.addSublayer(shapeLayer)
Upvotes: 2
Views: 2066
Reputation: 177
I guess you can scale the view that holds the path, like
let scaleWidth = toSize.width / fromSize.width
let scaleHeight = toSize.height / fromSize.height
path.apply(CGAffineTransform(scaleX: scaleWidth, y: scaleHeight))
and use the scale factor to get a certain point of the path too
Upvotes: 5