jacobsieradzki jacobsieradzki - 1 month ago 27
iOS Question

Remove border from UIBezierPath

I have drawn a very simple path using a UIBezierPath and a custom UIView subclass but for some reason, a border appears around the bounds of the view and I cannot seem to get rid of it or see why it was created.

I used this code:

private override func draw(_ rect: CGRect) {
let path = UIBezierPath(rect: CGRect(x: 15, y: 15, width: 300, height: 300))

path.move(to: CGPoint(x: 100, y: 100))
path.addLine(to: CGPoint(x: 150, y: 150))
path.addLine(to: CGPoint(x: 100, y: 200))
path.addLine(to: CGPoint(x: 150, y: 250))

path.lineWidth = 25.0

UIColor.darkGray.setStroke()
path.stroke()
}


and it gave this result... (the border should not be there, only the zig-zag line)

result

Any help please?

Answer

You're creating that rectangle by

let path = UIBezierPath(rect: CGRect(x: 15, y: 15, width: 300, height: 300))

you just need to do

let path = UIBezierPath()