     // create our own bezier path since we can control how it positions.
     
     convenience init(roundedRectWithoutAliasing frame: CGRect, byRoundingCorners corners: UIRectCorner, cornerRadius: CGFloat) {
-        let path = CGPathCreateMutable()
+        var path = CGMutablePath()
         
         func pointsForCorner(corner: UIRectCorner) -> (start: CGPoint, corner: CGPoint, end: CGPoint) {
             switch corner {
-            case UIRectCorner.TopLeft:
+            case UIRectCorner.topLeft:
                 return (
                     start: CGPoint(x: frame.minX, y: frame.midY),
                     corner: CGPoint(x: frame.minX, y: frame.minY),
                     end: CGPoint(x: frame.midX, y: frame.minY)
                 )
-            case UIRectCorner.TopRight:
+            case UIRectCorner.topRight:
                 return (
                     start: CGPoint(x: frame.midX, y: frame.minY),
                     corner: CGPoint(x: frame.maxX, y: frame.minY),
                     end: CGPoint(x: frame.maxX, y: frame.midY)
                 )
-            case UIRectCorner.BottomRight:
+            case UIRectCorner.bottomRight:
                 return (
                     start: CGPoint(x: frame.maxX, y: frame.midY),
                     corner: CGPoint(x: frame.maxX, y: frame.maxY),
                     end: CGPoint(x: frame.midX, y: frame.maxY)
                 )
-            case UIRectCorner.BottomLeft:
+            case UIRectCorner.bottomLeft:
                 return (
                     start: CGPoint(x: frame.midX, y: frame.maxY),
                     corner: CGPoint(x: frame.minX, y: frame.maxY),

        let path = UIBezierPath(roundedRectWithoutAliasing: CGRect(origin: CGPoint(), size: scaledSize), byRoundingCorners: roundedCorners, cornerRadius: scaledCornerRadius)
        
        foregroundColor.setFill()
        path.fillWithBlendMode(.Copy, alpha: 1.0)
        
        if let borderWidth = borderWidth {
            // border is drawn at twice the size because it draws outside the path half of it
            borderColor?.setStroke()
            path.addClip()
            path.lineWidth = min(borderWidth * screenScale, cornerRadius) * 2.0
            path.strokeWithBlendMode(.Copy, alpha: 1.0)
        }
        
        let rawImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        let image = UIImage(CGImage: rawImage.CGImage!, scale: screenScale, orientation: .Up)
        
        var capInsets = UIEdgeInsets()
        
        if resizingDirection.contains(.Vertical) {
            capInsets.top = cornerRadius
            capInsets.bottom = cornerRadius
        }
        
        if resizingDirection.contains(.Horizontal) {
            capInsets.left = cornerRadius
            capInsets.right = cornerRadius
        }
        
        return image.resizableImageWithCapInsets(capInsets, resizingMode: .Tile)
    }
}


            return (CGPoint(), CGPoint(), CGPoint())
        }
        
        for corner in [.topLeft, .topRight, .bottomRight, .bottomLeft] as [UIRectCorner] {
            let (startPoint, cornerPoint, endPoint) = pointsForCorner(corner: corner)
            if path.isEmpty {
                path.move(to: startPoint)
            }
            
            if corners.contains(corner) && cornerRadius > 0 {
                path.addArc(tangent1End: cornerPoint, tangent2End: endPoint, radius: cornerRadius)
            } else {
                path.addLine(to: cornerPoint)
                path.addLine(to: endPoint)
            }
        }
        
        path.closeSubpath()
        
        self.init(cgPath: path)
    }
}
