Created
July 29, 2016 15:01
-
-
Save jon-1/16eabdc55ae2767b6f1231e94e8933fb to your computer and use it in GitHub Desktop.
Round only top or bottom corners of a UIView
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
extension UIView { | |
enum Corners { | |
case Top | |
case Bottom | |
} | |
func roundCorners(radius : CGFloat, corners : Corners) { | |
let radius : CGFloat = radius | |
var maskFrame = self.bounds | |
maskFrame.size.height += radius | |
if corners == .Bottom { maskFrame.origin.y -= radius } | |
let maskLayer : CALayer = CALayer() | |
maskLayer.backgroundColor = UIColor.whiteColor().CGColor | |
maskLayer.cornerRadius = radius | |
maskLayer.frame = maskFrame | |
self.layer.mask = maskLayer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment