如何在 Interface Builder 中存储 key/value 并在运行时访问它们?

How to store key/value in Interface Builder and access them during runtime?

我想为我的一些不同类型的 UIView(在界面构建器中设置)存储帮助文本,并在运行时访问它们以将它们显示给用户。那可能吗?我知道用户定义的运行时属性只有在作为 UIView 的 属性 存在时才能使用。还有别的办法吗?

谢谢

您可以为其使用 Interface Builder 可设计宏。

创建自定义的 class,例如 TestViewClass,并用 IBInspectable 定义 属性。

在 Interface Builder 中将自定义 class 设置为某些 UIView,然后您将看到可以通过 IB

设置 属性
IB_DESIGNABLE
@interface TestViewClass : UIView

@property (strong, nonatomic) IBInspectable NSString *helpText;

@end