Skip to content

Instantly share code, notes, and snippets.

@mteera
Last active January 5, 2018 09:44
Show Gist options
  • Save mteera/f83b0648802e706bcd280e3cc9548b2c to your computer and use it in GitHub Desktop.
Save mteera/f83b0648802e706bcd280e3cc9548b2c to your computer and use it in GitHub Desktop.
An extension to create rounded corners on particular edges.
import UIKit
extension UIView {
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
// Usage: view.roundCorners([.bottomRight, .topRight], radius: 5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment