如何用虚线和普通线填充箭头的颜色

时间:2018-12-28 06:12:05

标签: ios swift

我想用填充的箭头创建贝塞尔曲线虚线和普通线。

 func addDashed_Arrow(start: CGPoint, end: CGPoint, pointerLineLength: CGFloat, arrowAngle: CGFloat) {
        self.move(to: start)
        self.addLine(to: end)
        let  dashes: [ CGFloat ] = [ 7.0, 6.0 ]
        self.setLineDash(dashes, count: dashes.count, phase: 0.0)

        let startEndAngle = atan((end.y - start.y) / (end.x - start.x)) + ((end.x - start.x) < 0 ? CGFloat(Double.pi) : 0.0)
        let arrowLine1 = CGPoint(x: end.x + pointerLineLength * cos(CGFloat(Double.pi) - startEndAngle + arrowAngle), y: end.y - pointerLineLength * sin(CGFloat(Double.pi) - startEndAngle + arrowAngle))
        let arrowLine2 = CGPoint(x: end.x + pointerLineLength * cos(CGFloat(Double.pi) - startEndAngle - arrowAngle), y: end.y - pointerLineLength * sin(CGFloat(Double.pi) - startEndAngle - arrowAngle))

        self.addLine(to: arrowLine1)
        self.move(to: end)
        self.addLine(to: arrowLine2)
        self.lineWidth = 4.0
        self.lineJoinStyle = .round
        self.lineCapStyle = .round
        self.stroke()

    }

enter image description here

0 个答案:

没有答案