jacobsieradzki
jacobsieradzki

Reputation: 1108

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?

Upvotes: 0

Views: 861

Answers (2)

Behrad3d
Behrad3d

Reputation: 439

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()

Upvotes: 3

James P
James P

Reputation: 4850

You are initialising the path with a rect, which gets drawn with the stroke. Just replace your first line with this:

let path = UIBezierPath()

Upvotes: 3

Related Questions