Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Created March 30, 2019 14:28
Show Gist options
  • Select an option

  • Save lamprosg/5e2b13da8a06e60ac1ebce6f2168f2f2 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/5e2b13da8a06e60ac1ebce6f2168f2f2 to your computer and use it in GitHub Desktop.
(iOS) View rounded corners
import UIKit
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
}
func makeCircle() {
if self.superview == nil {
print("must call add subview first")
return
}
roundCorners(corners: [.topLeft, .topRight, .bottomLeft, .bottomRight],
radius: self.frame.height / 2.0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment