-3

I want my UIView round from top right and top left only

view.layer.cornerRadius = 10
  • specify the iOS version being targeted, for iOS 11 n above, it can be as straight forward as `view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]` – Sandeep Bhandari Feb 12 '21 at 07:18

1 Answers1

3

Extension of UIView

extension UIView{

 func roundCorners(corners: UIRectCorner, radius: CGFloat) {
         let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
         let mask = CAShapeLayer()
         mask.path = path.cgPath
         layer.mask = mask
     }
}

call function for your view

topView.roundCorners(corners: [.topLeft,.topRight], radius: 8)
ajay negi
  • 604
  • 6
  • 12