How to load an XIB view as a subtask into an XIB view controller

I have a custom view that I made with the IB file, as it is rather complicated: (RotatorView.xib / .h / .m). I want to add RotatorView as a subtask to the view controller. I can do this programmatically using:

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

But I would rather not do this. It would be better for my design if I could add a RotatorView to the View Viewer canvas in Interface Builder. That way, I could use IB to manage the properties of each instance of RotatorView instead of setting the properties programmatically in each class. Is there a way so that I can add my custom view from XIB to the parent controller? Should I create an IB plugin for this?

+4
source share
1 answer

You can add the 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 invoking the loadNibNamed method programmatically, you cannot set custom properties directly from IB.

The only solution for this is to build an IB plugin , but unfortunately it seems you cannot make Cocoa Touch IB plugins because you cannot make Cocoa touch frames.

+4
source

Source: https://habr.com/ru/post/1332833/


All Articles