Skip to content

Instantly share code, notes, and snippets.

@ryantxr
Created March 26, 2016 07:44
Show Gist options
  • Save ryantxr/715fc70512c07ddc16a2 to your computer and use it in GitHub Desktop.
Save ryantxr/715fc70512c07ddc16a2 to your computer and use it in GitHub Desktop.
Swift extension for iOS to allow setting borders
extension UIView {
public func addTopBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.CGColor
border.frame = CGRectMake(0, 0, self.frame.size.width, width)
self.layer.addSublayer(border)
}
public func addRightBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.CGColor
border.frame = CGRectMake(self.frame.size.width - width, 0, width, self.frame.size.height)
self.layer.addSublayer(border)
}
public func addBottomBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.CGColor
border.frame = CGRectMake(0, self.frame.size.height - width, self.frame.size.width, width)
self.layer.addSublayer(border)
}
public func addLeftBorderWithColor(color: UIColor, width: CGFloat) {
let border = CALayer()
border.backgroundColor = color.CGColor
border.frame = CGRectMake(0, 0, width, 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