For getting the xib file from the resources, the following line of code is used :

[[NSBundle mainBundle] loadNibNamed:@”myXIBName” owner:self options:nil];

Now in order to get the main view of the XIB, use the following code :

UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@”myXIBName”owner:self options:nil] objectAtIndex:0];

The above code will load the main view that is added in the xib file to the UIView object, myView.

We can add this UIView object to the Cocos2D scene as follows :

[[[CCDirector sharedDirector] openGLView] addSubview:myView];

Incoming search terms:

  • cocos2d x add uiview
  • cocos2dx objective-c uiview
  • how to create a new xib file and object in cocos2d tutorial

Tagged with:

Filed under: Box 2dCocoaCocos2diPadiPhoneNews and EventsObjective CTips and Tricks

Like this post? Subscribe to my RSS feed and get loads more!