Skip to content

Instantly share code, notes, and snippets.

@jimmythai
Created April 23, 2019 12:11
Show Gist options
  • Save jimmythai/5c2c6d0fec596c7d0314f9f94fa94f2d to your computer and use it in GitHub Desktop.
Save jimmythai/5c2c6d0fec596c7d0314f9f94fa94f2d to your computer and use it in GitHub Desktop.
extension UIView {
enum BorderSide {
case left
case right
case top
case bottom
}
func addBorder(toSide side: BorderSide, withColor color: UIColor, withThickness thickness: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
switch side {
case .left:
border.frame = CGRect(x: frame.minX, y: frame.minY, width: thickness, height: frame.size.height)
case .right:
border.frame = CGRect(x: frame.maxX, y: frame.minY, width: thickness, height: frame.size.height)
case .top:
border.frame = CGRect(x: frame.minX, y: frame.minY, width: frame.size.width, height: thickness)
case .bottom:
border.frame = CGRect(x: frame.minX, y: frame.maxY, width: frame.size.width, height: thickness)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment