Xcode 13.4, MacOS 12.4, 07082022
This is the answer that creatively solved the problem without requiring a computed property. It works with layer.borderColor
in the User Defined Runtime Attributes
to add a border color to any, UIView.
Łukasz-kalbarczykenter
https://mcmap.net/q/262749/-uiview-39-s-border-color-in-interface-builder-doesn-39-t-work
It traps the setting of each runtime attribute and traps for the key name of borderColor
. If we have a match, it returns the cgColor value for
borderColor from the supplied UIColor.
Here is my updated answer from the work of Łukasz-kalbarczykenter
All I changed was set the extension to CALayer from UIView and made sure to use self.border
import UIKit
extension CALayer {
open override func setValue(_ value: Any?, forKey key: String) {
guard key == "borderColor", let color = value as? UIColor else {
super.setValue(value, forKey: key)
return
}
self.borderColor = color.cgColor
}
}
Next, in the storyboard, just select your UIView, press command option 4 and just add layer.borderColor
as your desired UIColor to the User Defined Runtime Attributes. Then run your app and it should work!
layer.borderColor
my border has disappeared – Lenhard