aghanim aghanim - 4 months ago 20
Swift Question

UIBezierPath - Swift 2

The following code creates the effect below:

let path = UIBezierPath()
path.moveToPoint(CGPoint(x: 0, y: 0))
path.addLineToPoint(CGPoint(x: headerRect.width, y: 0))
path.addLineToPoint(CGPoint(x: headerRect.width, y: headerRect.height))
path.addLineToPoint(CGPoint(x: 0, y: headerRect.height-headerCutAway))
headerMaskLayer?.path = path.CGPath


Effect on Image

I would like to change it so that the triangle is on the right rather on the left, how can I do that?

Rob Rob
Answer

Just swap the y value for the last two coordinates:

path.moveToPoint(CGPoint(x: 0, y: 0))
path.addLineToPoint(CGPoint(x: headerRect.width, y: 0))
path.addLineToPoint(CGPoint(x: headerRect.width, y: headerRect.height-headerCutAway))
path.addLineToPoint(CGPoint(x: 0, y: headerRect.height))
headerMaskLayer?.path = path.CGPath