Created
March 30, 2019 14:28
-
-
Save lamprosg/5e2b13da8a06e60ac1ebce6f2168f2f2 to your computer and use it in GitHub Desktop.
(iOS) View rounded corners
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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