Created
August 28, 2015 15:15
-
-
Save lukewakeford/fc2da7b95e6a68c0a8f8 to your computer and use it in GitHub Desktop.
UIView Borders
This file contains 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 { | |
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