Skip to content

Instantly share code, notes, and snippets.

@lukewakeford
Created August 28, 2015 15:15
Show Gist options
  • Save lukewakeford/fc2da7b95e6a68c0a8f8 to your computer and use it in GitHub Desktop.
Save lukewakeford/fc2da7b95e6a68c0a8f8 to your computer and use it in GitHub Desktop.
UIView Borders
extension UIView {
func roundCorners(corners:UIRectCorner, radius:CGFloat) {
let bounds = self.bounds;
let maskPath:UIBezierPath = UIBezierPath(roundedRect: bounds, byRoundingCorners: corners, cornerRadii: CGSizeMake(radius, radius))
let maskLayer:CAShapeLayer = CAShapeLayer()
maskLayer.frame = bounds
maskLayer.path = maskPath.CGPath
self.layer.mask = maskLayer
let frameLayer = CAShapeLayer()
frameLayer.frame = bounds
frameLayer.path = maskPath.CGPath
if let bgc = self.backgroundColor {
frameLayer.strokeColor = bgc.CGColor
}
frameLayer.fillColor = nil
self.layer.addSublayer(frameLayer)
}
func roundTopCornersRadius(radius:CGFloat) {
self.roundCorners((UIRectCorner.TopLeft|UIRectCorner.TopRight), radius:radius)
}
func roundBottomCornersRadius(radius:CGFloat) {
self.roundCorners((UIRectCorner.BottomLeft|UIRectCorner.BottomRight), radius:radius)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment