Last active
January 16, 2016 00:15
-
-
Save anthonycastelli/9290698cc3dd397359a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You'll need this https://gist.github.com/jorgenisaksson/76a8dae54fd3dc4e31c2 | |
extension NSBezierPath { | |
func toCGPath () -> CGPath? { | |
if self.elementCount == 0 { | |
return nil | |
} | |
let path = CGPathCreateMutable() | |
var didClosePath = false | |
for i in 0...self.elementCount-1 { | |
var points = [NSPoint](count: 3, repeatedValue: NSZeroPoint) | |
switch self.elementAtIndex(i, associatedPoints: &points) { | |
case .MoveToBezierPathElement:CGPathMoveToPoint(path, nil, points[0].x, points[0].y) | |
case .LineToBezierPathElement:CGPathAddLineToPoint(path, nil, points[0].x, points[0].y) | |
case .CurveToBezierPathElement:CGPathAddCurveToPoint(path, nil, points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, points[2].y) | |
case .ClosePathBezierPathElement:CGPathCloseSubpath(path) | |
didClosePath = true; | |
} | |
} | |
if !didClosePath { | |
CGPathCloseSubpath(path) | |
} | |
return CGPathCreateCopy(path) | |
} | |
} | |
var isFirst = false { | |
didSet { | |
if isFirst { | |
let mask = NSBezierPath(roundedRect: NSRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height + 10), xRadius: 10.0, yRadius: 10.0) | |
mask.fill() | |
let maskShape = CAShapeLayer() | |
maskShape.path = mask.toCGPath() | |
self.layer?.mask = maskShape | |
} else { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment