I'm using this CALayer extension:
var borderUIColor: UIColor {
set {
self.borderColor = newValue.cgColor
}
get {
return UIColor(cgColor: self.borderColor!)
}
}
I thought that maybe because of this extension my borderColor of the Submit button from the bottom of the page doesn't change to white (as I want it to be):
But no, I hooked up an IBOutlet and tried to set directly the color like this:
submitButton.layer.borderColor = UIColor.white.cgColor
Did it in viewDidLoad, viewWillAppear and viewDidAppear because I know that in the last big update (iOS 10) the frame rendering was changed fundamentally (the 1000x1000 frame thing) and maybe there were some similar alterations now. No luck, though.
I tested in iOS 9, 10 and 11. It's not about the OS, rather about the environment. I'm using Xcode 9 Beta 5. Any ideas how to solve it?
try decorating your var declaration with @objc like so:
@objc var borderUIColor: UIColor {
...
}
that should fix your problem
Cleared the project, deleted the derived data and the code works now, in either viewDidLoad, viewWillAppear or viewDidAppear.
The issue is apparently with the User Defined Runtime Attributes. Xcode 9 no longer accepts extension vars here. Or, at least, the Beta 5 version.
EDIT: Indeed, adding @objc solves the issue.
Just faced the same issue, and got another solution: I just made my class KVC-compliant.
Sample, step-by-step:
- Custom class is XTCMenuItem, with property propIdentifier.
- For KVC-compliance, this class got the two methods:
- override func value(forKey key: String) -> Any?
- override func setValue(_ value: Any?, forKey key: String)
- In Identity Inspector, I set custom class to "XTCMenuItem", and add the user defined runtime attribute "propIdentifier" with type "String", and a string value.
If you don't want to create IBOutlet and just use RunTime Attributes, then you can use IBDesignable and set prefix @objc it will solve your problem.
@objc @IBInspectable var borderColor: UIColor {
get {
return UIColor(cgColor: self.layer.borderColor!)
}
set {
self.layer.borderColor = newValue.cgColor
}
}
Use @IBInspectable attribute. Example:
@IBInspectable var borderColor = UIColor.green
来源:https://stackoverflow.com/questions/45630049/xcode-9-bordercolor-doesnt-work-in-user-defined-runtime-attributes
