UIBezierPath - Swift 2
UIBezierPath - Swift 2
以下代码创建如下效果:
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
我想改变它,让三角形在右边而不是左边,我该怎么做?
只需交换最后两个坐标的 y
值:
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
以下代码创建如下效果:
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
我想改变它,让三角形在右边而不是左边,我该怎么做?
只需交换最后两个坐标的 y
值:
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