【发布时间】:2024-12-03 06:05:01
【问题描述】:
我有许多方向和角度的线条,我使用UIBezierpath 绘制它们。
我需要在线条的一端画一个箭头;根据给定点动态变化。
编辑 2: 杰克回答这里是我的代码
let y2 = line.point2Y
let path = UIBezierPath()
path.move(to: CGPoint(x: x1, y: y1))
path.addLine(to: CGPoint(x: x2, y: y2))
path.addArrow(start: CGPoint(x: x1, y: y1), end: CGPoint(x: x2, y: y2), pointerLineLength: ...
path.close()
let shape = CAShapeLayer()
let shapeBorder = CAShapeLayer()
shapeBorder.strokeColor = UIColor.black.cgColor
shapeBorder.lineJoin = kCALineJoinRound
shapeBorder.lineCap = kCALineCapRound
shapeBorder.lineWidth = 10
shapeBorder.addSublayer(shape)
shape.path = path.cgPath
shapeBorder.path = shape.path
shape.lineJoin = kCALineJoinRound
shape.lineCap = kCALineCapRound
shape.lineWidth = shapeBorder.lineWidth-5.0
shape.strokeColor = color
【问题讨论】:
-
我会检查的,谢谢
-
需要更多信息...箭头大小、箭头方向、箭头位置等
-
方向是动态的,可以指向360度的任意角度。
-
大小无关紧要,箭头的尖端将始终是任何线的 2 个点之一
-
请将您的代码放在问题中的文本中,而不是图像中。您的问题是您所在图层的
fillColor。将其设置为UIColor.clear.cgColor
标签: ios swift3 uibezierpath