Skip to content

Instantly share code, notes, and snippets.

@mudasir093
Created October 16, 2019 14:49
Show Gist options
  • Save mudasir093/204f7a84fa8f038717eb8424c3b57a2d to your computer and use it in GitHub Desktop.
Save mudasir093/204f7a84fa8f038717eb8424c3b57a2d to your computer and use it in GitHub Desktop.
UIView Border Extension
//Extension for add border in view
extension UIView {
// Extension for Top Border
func addTopBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: 0, y: 0, width: self.frame.size.width, height: width)
self.layer.addSublayer(border)
}
// Extension for Right Border
func addRightBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: self.frame.size.width - width, y: 0, width: width, height: self.frame.size.height)
self.layer.addSublayer(border)
}
// Extension for Bottom Border
func addBottomBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: 0, y: self.frame.size.height - width, width: self.frame.size.width, height: width)
self.layer.addSublayer(border)
}
// Extension for Left Border
func addLeftBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.cgColor
border.frame = CGRect(x: 0, y: 0, width: width, height: self.frame.size.height)
self.layer.addSublayer(border)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment