如何将视图 XIB 作为子视图加载到视图控制器 XIB 中
我有一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 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.