I made a extension of CALayer for border color as a runtime attribute, but it is not working.
It shows default black color only.
extension CALayer {
var borderUIColor: UIColor {
set {
self.borderColor = newValue.cgColor
}
get {
return UIColor(cgColor: self.borderColor!)
}
}
}

You should handle nil values with care, and may create an extension to UIView which declares the property as @IBInspectabe:
import UIKit
extension UIView {
@IBInspectable var borderColor: UIColor? {
get {
if let color = layer.borderColor {
return UIColor(cgColor: color)
}
else {
return nil
}
}
set { layer.borderColor = newValue?.cgColor }
}
}
This makes it much easier to set the border color in Attribute Inspector.
EDIT: Your example works for me with Xcode 9.0 and 8.3.3 as well. Probably it was a bug in a beta version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With