I need to create a button with top-left & bottom-left corner radius like this one . I tried by creating the following extension that was taken from one of stackoverflow
Your code is applying a mask layer to your button. that causes anything outside the shape you install in the mask layer to be masked away. When you install a path with rounded corners, it essentially "shaves off" the 2 corners. That's not what you want.
You probably want to create a shape layer and install it as a regular sublayer of your button's layer, not as the mask layer. You'll need to set the fill color to clear however.
Change your code like this:
extension UIButton
{
func roundCorners(corners:UIRectCorner, radius: CGFloat)
{
let borderLayer = CAShapeLayer()
borderLayer.frame = self.layer.bounds
borderLayer.strokeColor = GenerateShape.UIColorFromHex(0x989898,
alpha: (1.0-0.3)).CGColor
borderLayer.fillColor = UIColor.clearColor().CGColor
borderLayer.lineWidth = 1.0
let path = UIBezierPath(roundedRect: self.bounds,
byRoundingCorners: corners,
cornerRadii: CGSize(width: radius, height: radius))
borderLayer.path = path.CGPath
self.layer.addSublayer(borderLayer);
}
}
Your syntax for setting the corners won't work in Swift 2:
self.collectionBtn.roundCorners(.TopLeft | .BottomLeft, radius: 10)
Should be
self.collectionBtn.roundCorners([.TopLeft, .BottomLeft], radius: 10)