Last active
May 18, 2019 03:13
-
-
Save adamgraham/f27e0a8ce0eb26d8dfcea58f7026bb4b to your computer and use it in GitHub Desktop.
An @IBDesignable extension of the iOS class UIView to provide customization of borders within Interface Builder.
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
protocol DesignableBorder { | |
var cornerRadius: CGFloat { get set } | |
var borderWidth: CGFloat { get set } | |
var borderColor: UIColor? { get set } | |
} | |
@IBDesignable extension UIView: DesignableBorder { | |
@IBInspectable var cornerRadius: CGFloat { | |
get { return self.layer.cornerRadius } | |
set { self.layer.cornerRadius = newValue } | |
} | |
@IBInspectable var borderWidth: CGFloat { | |
get { return self.layer.borderWidth } | |
set { self.layer.borderWidth = newValue } | |
} | |
@IBInspectable var borderColor: UIColor? { | |
get { | |
guard let cgColor = self.layer.borderColor else { return nil } | |
return UIColor(cgColor: cgColor) | |
} | |
set { self.layer.borderColor = newValue?.cgColor } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment