This is my code:
let cross = UIBezierPath()
cross.move(to: CGPoint(x: skull.bounds.maxX, y: skull.bounds.minY))
cross.addLine(to: CGPoint(x: skull.bounds.minX, y: skull.bounds.maxY))
cross.close()
UIColor.red.set()
cross.lineWidth = 3.0
cross.lineCapStyle = .round
cross.stroke()
I want to round the end of the line, but it's still square, how should I do it?
A single Bézier path object can contain any number of open or closed subpaths, where each subpath represents a connected series of path segments. Calling the close () method closes a subpath by adding a straight line segment from the current point to the first point in the subpath.
A UIBezierPath object combines the geometry of a path with attributes that describe the path during rendering. You set the geometry and attributes separately and can change them independent of one another. After you have the object configured the way you want it, you can tell it to draw itself in the current context.
Because the creation, configuration, and rendering process are all distinct steps, Bézier path objects can be reused easily in your code. You can even use the same object to render the same shape multiple times, perhaps changing the rendering options between successive drawing calls.
A path that consists of straight and curved line segments that you can render in your custom views. You use this class initially to specify just the geometry for your path.
just tested on PlayGround, Hope it will help
let cross = UIBezierPath()
cross.moveToPoint(CGPoint(x: 10, y: 100)) // your point
cross.addLineToPoint(CGPoint(x: 100, y: 10)) // your point
cross.closePath()
cross.lineWidth = 23.0
cross.lineJoinStyle = .Round
cross.stroke()
Result
The line cap style configures the style of the line ending. You have closed path, i.e. you have no line ending.
You are probably looking for the line join style, which affects all "corners" or "vertexes" of a path.
Alternatively, if you just want a straight, don't close the path. Otherwise you get two line segments: one from the starting point to the end point and another one back to the start.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With