         let path = UIBezierPath(roundedRectWithoutAliasing: CGRect(origin: CGPoint(), size: scaledSize), byRoundingCorners: roundedCorners, cornerRadius: scaledCornerRadius)
         
         foregroundColor.setFill()
-        path.fillWithBlendMode(.Copy, alpha: 1.0)
+        path.fill(with: .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)
+            path.stroke(with: .copy, alpha: 1.0)
         }
         
-        let rawImage = UIGraphicsGetImageFromCurrentImageContext()
+        let rawImage = UIGraphicsGetImageFromCurrentImageContext()!
         UIGraphicsEndImageContext()
         
-        let image = UIImage(CGImage: rawImage.CGImage!, scale: screenScale, orientation: .Up)
+        let image = UIImage(cgImage: rawImage.cgImage!, scale: screenScale, orientation: .up)
         
         var capInsets = UIEdgeInsets()
         
-        if resizingDirection.contains(.Vertical) {
+        if resizingDirection.contains(.vertical) {
             capInsets.top = cornerRadius
             capInsets.bottom = cornerRadius
         }
         
-        if resizingDirection.contains(.Horizontal) {
+        if resizingDirection.contains(.horizontal) {
             capInsets.left = cornerRadius
             capInsets.right = cornerRadius
         }
         
-        return image.resizableImageWithCapInsets(capInsets, resizingMode: .Tile)
+        return image.resizableImage(withCapInsets: capInsets, resizingMode: .tile)
     }
 }
 

import UIKit

public struct RoundedResizingDirection : OptionSetType {
    public let rawValue: Int
    public init(rawValue: Int) {
        self.rawValue = rawValue
    }
    
    public static let Horizontal = RoundedResizingDirection(rawValue: 0b1)
    public static let Vertical = RoundedResizingDirection(rawValue: 0b10)
    public static let Both: RoundedResizingDirection = [Horizontal, Vertical]
}

extension UIColor {

    // and the language does not allow this
    public static func imageWithRoundedCorners(roundedCorners: UIRectCorner, cornerRadius: CGFloat, resizingDirection: RoundedResizingDirection, foregroundColor: UIColor, backgroundColor: UIColor, borderColor: UIColor? = nil, borderWidth: CGFloat? = nil) -> UIImage {
        // We adjust all our values to be in 1.0-scale space so smaller radii are less aliased
        let screenScale = UIScreen.main.scale
        let scaledCornerRadius = cornerRadius * screenScale
        var scaledSize = CGSize(width: scaledCornerRadius*2.0, height: scaledCornerRadius*2.0)
        
        if resizingDirection.contains(.horizontal) {
            scaledSize.width += screenScale
        }
        
        if resizingDirection.contains(.vertical) {
            scaledSize.height += screenScale
        }
        
