Created
March 26, 2016 07:44
-
-
Save ryantxr/715fc70512c07ddc16a2 to your computer and use it in GitHub Desktop.
Swift extension for iOS to allow setting borders
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 { | |
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