Interface Builder - How to create a custom UIView with many subviews

How to create a custom UIView (with many subviews, UITextFields, etc.) in an interface constructor?

I do not want the viewController with NIB to be just a simple UIView, with a lot of subviews created in IB, which I can just assign init and use, is this possible?

+4
source share
1 answer

Yes, you can create a UIView in nib - when you create a view-based nib, what you create is a UIView. There is no view controller (although often you create a controller of the form File Owner of the nib).

You will need to create your own view class and change the view class from xib to this custom class in order to include IBOutlets in that view. If you want to use the view in the controller, you can create it as follows:

UINib *nib = [UINib nibWithNibName:@"CustomView" bundle:nil]; CustomView *view = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0]; 

The limitation of this method is that your outputs belong to the view class and not to the view controller, which cannot (but may be) be correct in the sense of MVC.

+16
source

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


All Articles