1

I am trying to do the following:

  1. Display an instance of a custom UIView. This UIView subclass should load it's content from Interface Builder, because it shows stuff that I don't want to create by hand. My question is: How can I load from Interface Builder in a UIView subclass?

  2. I will eventually animate this view out of the screen and release it. (I know how to do that :-) )

  3. GOTO Step 1, i.e creating a new instance of my UIView and display it.

Probably a noobish question, but I can't seem to figure it out. I would appreciate some help, Fabian

2 Answers 2

3

In iOS 4.0+, create an instance of UINib referencing your nib file (+nibWithNibName:bundle:), then instantiate the objects in the nib with -[UINib instantiateWithOwner:options:].

If you need to target iOS 3.x, too, call:

[[NSBundle mainBundle] loadNibNamed:owner:options:]

which returns an array of the objects in the nib file.

2
  • I have used this approach, but I have not succeeded in making the corners of the rounded edged view transparent. My NIB loaded custom UIView is a cornered rectangle, not a rounded rectangle. Any suggestions?
    – maralbjo
    Jan 18, 2011 at 19:22
  • What does one have to do with the other? Jan 18, 2011 at 21:24
1

To load an interface from Interface Builder you need to use a UIViewController. If you don't use interface builder though, you can create a uiview subclass, create your interface, and then create instances of your class. For every class all you need to do is this:

MyView *view = [[MYView alloc] initWithFrame:theFrame];
MyView *secondView = [[MyView alloc] initWithFrame:theFrame];
//do stuff with the views
//release the views
[view release];
[secondView release];
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.