Xcode 9 borderColor doesn't work in User Defined Runtime Attributes

爱⌒轻易说出口 提交于 2019-12-06 15:30:58

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!