Created
October 16, 2019 14:49
-
-
Save mudasir093/204f7a84fa8f038717eb8424c3b57a2d to your computer and use it in GitHub Desktop.
UIView Border Extension
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 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