For quick 3, Kirit Modi's answer changes to:
extension UIButton { func roundedButton(){ let maskPAth1 = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: [.topLeft , .topRight], cornerRadii:CGSize(width:8.0, height:8.0)) let maskLayer1 = CAShapeLayer() maskLayer1.frame = self.bounds maskLayer1.path = maskPAth1.cgPath self.layer.mask = maskLayer1 } }
At the beginning of the extension file, be sure to add:
import UIKit
If you want an extension for UIView with the ability to round the top or bottom corner, you can use:
extension UIView { func roundedCorners(top: Bool){ let corners:UIRectCorner = (top ? [.topLeft , .topRight] : [.bottomRight , .bottomLeft]) let maskPAth1 = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii:CGSize(width:8.0, height:8.0)) let maskLayer1 = CAShapeLayer() maskLayer1.frame = self.bounds maskLayer1.path = maskPAth1.cgPath self.layer.mask = maskLayer1 } }
What is called a button:
myButton.roundedCorners(top: true)
source share