ios - 如何在 Interface Builder 中存储键/值并在运行时访问它们?

标签 ios interface-builder

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

谢谢

最佳答案

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

创建名为 TestViewClass 的自定义类,并使用 IBInspectable 定义属性。

在 Interface Builder 中将自定义类设置为某个 UIView,然后您将看到可以通过 IB enter image description here 设置该属性

IB_DESIGNABLE
@interface TestViewClass : UIView

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

@end

关于ios - 如何在 Interface Builder 中存储键/值并在运行时访问它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33631983/

相关文章:

ios - Xcode 4.5 : can't set root view autoresizingMask in Interface Builder

ios - 如何使用自动布局隐藏标签

iphone - 如何加载本地化 Nib ?

ios - 将导航栏添加到没有导航 Controller 的 View Controller

ios - 核心数据按月和总和分组

ios - 如何从 system(); 获取日志?

ios - respondsToSelector 到 id 类型对象

iphone - 警告: Attempt to present ViewController on ViewController whose view is not in the window hierarchy

ios - AFNetworking 2.0 POST 问题 |替换已弃用的 multipartFormRequestWithMethod :path:parameters

swift - 使 UIButton 在 Interface Builder 中可访问