Skip to content

Instantly share code, notes, and snippets.

@filsv
Created December 26, 2016 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filsv/04e700ff9d5815af66aede5d1cc1393f to your computer and use it in GitHub Desktop.
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).
// 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