Directly drag custom xib in your view controller is not possible.But you can do one thing,drag its super class view and set its class to your custom class.And connect its properties to the objects you will place according to your Custom Class.
You can directly load your custom xib using following code:
//load xib using code ....
QSKey *keyView=[[QSKey alloc] init];
NSArray *topObjects=[[NSBundle mainBundle] loadNibNamed:@"QSKey" owner:self options:nil];
for (id view in topObjects) {
if ([view isKindOfClass:[QSKey class]]) {
keyView=(QSKey*)view;
}
}
keyView.label.text=@"CView";
[keyView setFrame:CGRectMake(0, 0, 100, 100)];
[keyView setBackgroundColor:[UIColor redColor]];
[self.view addSubview:keyView];
here label is UILabel object you have used in your custom class as its property.
//Load custom View using drag down objects of type Custom Class Super class.
for (QSKey *aView in self.view.subviews) {
if ([aView isKindOfClass:[QSKey class]]) {
[self addGestureRecognizersToPiece:aView];
aView.label.text=@"whatever!";
}
}
Here label is object of UILabel you have to place on your dragged View to view controller's xib view.Change that view's class to your Custom Class.Then it will will show its label property in outlet connect it to your UILabel object placed over dragged view.
Here is a working code TestTouchonView
And the Screenshot will display as follows.