Created
April 23, 2019 12:11
-
-
Save jimmythai/5c2c6d0fec596c7d0314f9f94fa94f2d to your computer and use it in GitHub Desktop.
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 { | |
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