             self.borderAlignment = .Inside
 
             let imageSize: CGFloat
-            let capSize: CGFloat
-
-            if self.cornerRadius > 0 {
-                imageSize = self.cornerRadius * 2
-                capSize = self.cornerRadius
+            let cornerRadius = max(
+                self.cornerRadiusTopLeft, self.cornerRadiusTopRight,
+                self.cornerRadiusBottomLeft, self.cornerRadiusBottomRight
+            )
+
+            if cornerRadius > 0 {
+                imageSize = cornerRadius * 2
             } else {
-                imageSize = self.borderWidth * 2 + 1
-                capSize = self.borderWidth
+                imageSize = borderWidth * 2 + 1
             }
 
             let image = self.imageWithSize(CGSize(width: imageSize, height: imageSize))
-            let capInsets = UIEdgeInsets(top: capSize, left: capSize, bottom: capSize, right: capSize)
+            let capInsets = UIEdgeInsets(
+                top: max(self.cornerRadiusTopLeft, self.cornerRadiusTopRight),
+                left: max(self.cornerRadiusTopLeft, self.cornerRadiusBottomLeft),
+                bottom: max(self.cornerRadiusBottomLeft, self.cornerRadiusBottomRight),
+                right: max(self.cornerRadiusTopRight, self.cornerRadiusBottomRight)
+            )
             return image.resizableImageWithCapInsets(capInsets)
         }
     }

    private var borderColor = UIColor.blackColor()
    private var borderWidth: CGFloat = 0
    private var borderAlignment: BorderAlignment = .Inside
    private var cornerRadius: CGFloat = 0
    private var size: Size = .Resizable



            imageSize.height += self.borderWidth * 2
        }

        let cornerRadius = max(
            self.cornerRadiusTopLeft, self.cornerRadiusTopRight,
            self.cornerRadiusBottomLeft, self.cornerRadiusBottomRight
        )

        var image = UIImage.with(size: imageSize) { context in
            self.color.setFill()
            self.borderColor.setStroke()

            let path: UIBezierPath
            if cornerRadius > 0 {
                let startAngle = CGFloat(M_PI)

                let topLeftCenterX = self.cornerRadiusTopLeft + self.borderWidth / 2
                let topLeftCenterY = self.cornerRadiusTopLeft + self.borderWidth / 2

                let topRightCenterX = imageSize.width - self.cornerRadiusTopRight - self.borderWidth / 2
                let topRightCenterY = self.cornerRadiusTopRight + self.borderWidth / 2

                let bottomRightCenterX = imageSize.width - self.cornerRadiusBottomRight - self.borderWidth / 2
                let bottomRightCenterY = imageSize.height - self.cornerRadiusBottomRight - self.borderWidth / 2

                let bottomLeftCenterX = self.cornerRadiusBottomLeft + self.borderWidth / 2
                let bottomLeftCenterY = imageSize.height - self.cornerRadiusBottomLeft - self.borderWidth / 2

                var mutablePath = UIBezierPath()
                mutablePath.addArcWithCenter(CGPoint(x: topLeftCenterX, y: topLeftCenterY),
                    radius: self.cornerRadiusTopLeft,
                    startAngle: startAngle,
                    endAngle: 1.5 * startAngle,
                    clockwise: true
                )
                mutablePath.addArcWithCenter(CGPoint(x: topRightCenterX , y: topRightCenterY),
                    radius: self.cornerRadiusTopRight,
                    startAngle: 1.5 * startAngle,
                    endAngle: 2 * startAngle,
                    clockwise: true
                )
                mutablePath.addArcWithCenter(CGPoint(x: bottomRightCenterX , y: bottomRightCenterY),
                    radius: self.cornerRadiusBottomRight,
                    startAngle: 2 * startAngle,
                    endAngle: 2.5 * startAngle,
                    clockwise: true
                )
                mutablePath.addArcWithCenter(CGPoint(x: bottomLeftCenterX , y: bottomLeftCenterY),
                    radius: self.cornerRadiusBottomLeft,
                    startAngle: 2.5 * startAngle,
                    endAngle: 3 * startAngle,
                    clockwise: true
                )
                mutablePath.addLineToPoint(CGPoint(x: self.borderWidth / 2, y: topLeftCenterY))
                path = mutablePath
            } else {
                path = UIBezierPath(rect: rect)
            }
