在UIBezierPath上拆分行

时间:2017-12-14 10:58:09

标签: ios swift split

我创建了一个形状,并在其中使用UIBezierPath创建了不同的细分。我需要在每个片段的末尾画一条线o甜甜圈看起来像是被分割了。

我该如何绘制该线?

1 个答案:

答案 0 :(得分:3)

以下是绘制线条的代码。

//object of UIBezierPath
let path = UIBezierPath()

//Moves the receiver’s current point to the specified location.
path.move(to: CGPoint(x: 100, y: 200))

//Appends a straight line to the receiver’s path
path.addLine(to: CGPoint(x: 200, y: 200))
path.addLine(to: CGPoint(x: 200, y: 300))
path.addLine(to: CGPoint(x: 100, y: 300))
path.addLine(to: CGPoint(x: 100, y: 200))


//below code for draw line with use of path which is above code
let progressLine = CAShapeLayer()
progressLine.path = path.cgPath
progressLine.strokeColor = UIColor.blue.cgColor
progressLine.fillColor = UIColor.red.cgColor
progressLine.lineWidth = 10.0[![enter image description here][1]][1]
progressLine.lineCap = kCALineCapRound

// add the curve to the screen
self.view.layer.addSublayer(progressLine)

这看起来像下图 enter image description here