ios - 在设计时设置的 IBInspectable 属性不保持值

标签 ios xcode interface-builder ibdesignable ibinspectable

我们正在将 IBInspectable 实现到一个大型应用程序中,希望允许在 Interface Builder 中设置一些设置以减少我们 View 中的代码量。我对 IBInspectable/IBDesignable 没有太多经验,正在寻找一些答案和/或澄清我做错了什么。

我在 UITableViewCell 子类中声明了一个属性,如下所示:

@property (nonatomic,strong) IBInspectable UIColor* backgroundColor;

当像这样声明属性时,我可以选择在 Interface Builder > Attributes Inspector 中设置该颜色,这是意料之中的。但是,当我设置颜色时,_backgroundColor 的值在运行时为 nil。

[_labelLoginBackground setBackgroundColor:_backgroundColor];

有人可以澄清这里可能发生的事情吗?谢谢!

最佳答案

UITableViewCell 是 UIView 的子类,它已经包含一个名为“backgroundColor”的属性。执行以下操作之一:

  1. 将您自己的“backgroundColor”属性重命名为“loginBackgroundColor”并从那里开始调试。

  1. 不要创建多余的属性。在添加 IBInspectable 之前,使用已存在于 Interface Builder 中的选择小部件设置背景颜色。

enter image description here

关于ios - 在设计时设置的 IBInspectable 属性不保持值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31463581/

相关文章:

ios - 无法添加构建以测试内部测试人员

ios - 自动布局以保持 View 大小成比例

iPhone通用静态库在发布配置的Interface Builder中工作,但在调试中不起作用

ios - Xcode 图像目录 : Image not showing in Interface Builder

ios - 重定向到另一个 View Controller

iOS:使用没有核心数据的动画更新表格 View 数据源

android - react native : set different variable in iOS/Android builds

ios - Swift:如果我在变量中有实例的名称,如何创建类的实例?

ios - RubyMotion 错误

ios - 如何在 Swift 中使用函数更改标签后将其更改为原始文本?