Created
December 26, 2016 13:40
-
-
Save filsv/04e700ff9d5815af66aede5d1cc1393f to your computer and use it in GitHub Desktop.
Swift 3 Extension for Adding Border on one of the sides (or for all sides).
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
// Layer extension for adding border on one of the sides | |
extension CALayer { | |
func addBorder(edge: UIRectEdge, color: UIColor, thickness: CGFloat) { | |
let border = CALayer() | |
switch edge { | |
case UIRectEdge.top: | |
border.frame = CGRect.init(x: 0, y: 0, width: frame.width, height: thickness) | |
break | |
case UIRectEdge.bottom: | |
border.frame = CGRect.init(x: 0, y: frame.height - thickness, width: frame.width, height: thickness) | |
break | |
case UIRectEdge.left: | |
border.frame = CGRect.init(x: 0, y: 0, width: thickness, height: frame.height) | |
break | |
case UIRectEdge.right: | |
border.frame = CGRect.init(x: frame.width - thickness, y: 0, width: thickness, height: frame.height) | |
break | |
default: | |
break | |
} | |
border.backgroundColor = color.cgColor | |
self.addSublayer(border) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment