如何将视图 XIB 作为子视图加载到视图控制器 XIB 中

发布于 2024-10-08 17:09:03 字数 464 浏览 0 评论 0原文

我有一个用 IB 文件制作的自定义视图,因为它非常复杂:(RotatorView.xib/.h/.m)。 我想将 RotatorView 作为子视图添加到视图控制器中。我可以使用以下方式以编程方式执行此操作:

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"RotatorView" 
                                               owner:self options:nil];

但我不想这样做。如果我可以将 RotatorView 添加到 Interface Builder 中视图控制器的画布上,那对我的设计会更好。这样我就可以使用 IB 来管理 RotatorView 每个实例的属性,而不是在每个类中以编程方式设置属性。有没有办法可以将带有 XIB 的自定义视图添加到父视图控制器?我必须构建一个 IB 插件才能做到这一点吗?

I have a custom view I made with an IB file since it's quite complex: (RotatorView.xib/.h/.m).
I want to add the RotatorView as a subview to a view controller. I can do this programmatically using:

NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"RotatorView" 
                                               owner:self options:nil];

But I'd rather not do that. It would be better for my design if I could add the RotatorView to the canvas of a View Controller in Interface Builder. That way I could use IB to manage the properties of each instance of RotatorView instead of setting properties programmatically in each class. Is there a way that I can add my custom view with XIB to a parent view controller? Do I have to build an IB plugin to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

噩梦成真你也成魔 2024-10-15 17:09:03

您可以将 UIView 控件添加到 IB 中的画布并更改其类名称以匹配您的自定义视图类名称。
虽然这将使您免于以编程方式调用 loadNibNamed 方法,但您将无法直接从 IB 设置自定义属性。

执行此操作的唯一解决方案是构建 IB插件,但不幸的是,你似乎无法制作Cocoa Touch IB插件,因为你无法制作Cocoa Touch框架。

You can add a UIView control to the canvas in IB and change its class name to match your custom view class name.
Although this will save you from calling loadNibNamed method programmatically, but you'll not be able to set the custom properties directly from IB.

The only solution for doing this is to build an IB plugin, but unfortunately it seems you can't make Cocoa Touch IB plugins because you can't make Cocoa Touch frameworks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文