Search code examples
iosswiftuibezierpath

UIBezierPath Triangle reverse


Currently I am having a small issue. The code below will output an triangle shaped layer on top of my tableViewHeader but I want to reverse the cut direction of the bazier path.

Code:

let cutDirection = UIBezierPath()
cutDirection.move(to: CGPoint(x: 0, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: 0))
cutDirection.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height))
cutDirection.addLine(to: CGPoint(x: 0, y: headerRect.height - headerCut))
newHeaderLayer.path = cutDirection.cgPath

Outputs:

enter image description here

enter image description here

Result I am looking for:

Thanks for any help!

Kevin.


Solution

  • Try this:

    let cutDirection = UIBezierPath()
    cutDirection.move(to: CGPoint(x: 0, y: 0))
    cutDirection.addLine(to: CGPoint(x: headerRect.width, y: 0))
    cutDirection.addLine(to: CGPoint(x: headerRect.width, y: headerRect.height - headerCut))
    cutDirection.addLine(to: CGPoint(x: 0, y: headerRect.height))
    newHeaderLayer.path = cutDirection.cgPath