I found one way to do this to take the following steps:
- Create a new xib file and set Simulated Metrics to "Freeform" to allow resizing.
(MyControl.xib) - Fill the control with the objects that I want in the control.
- Create a UIViewController for the view.
(MyViewController.h & MyViewController.m) - Set
File Owner for MyControl.xib to the custom class MyViewController - In xib, which I want to include in the control, I put the UIScrollView where I need the control (regular view will work too). (
Parent.xib ) - Create an
IBOutlet for the UISCrollView into which I will ParentController control into the ParentController . - Create an instance of
MyViewController in the ParentController . - In the
ParentController add the MyViewController as a UISCrollView .
In code, this means
@implementation ParentController @synthesize myScrollView; MyViewController* myController; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super init]; if(self) { myController = [[MyController alloc] initWithNibName:@"MyView" bundle:nil]; [myScrollView addSubview:myController.view]; } }
This seems to work and allows me to separate the Control and parent implementation, but I can't help but think that there is a better way.
source share