Search code examples
iphonexcodexcode4interface-builder

Using Interface Builder to add subview


My questions below are about doing this with Interface Builder, not in code.

I have a XIB with two views. One of them is default view (Table View) and I add the second (Activity Indicator View) as a subview in code. my questions are:

  1. Is it possible to set the location of the second subview using IB, not in code? (i.e. can I remove the code line: activityIndicator.frame = CGRectMake(160, 240, 30, 30);)
  2. Is it possible to add the second subview as a subview using Interface Builder? (i.e.e can I remove the code [self.view addSubview:self.activityIndicator])

Solution

  • Yes, to both questions.

    The xib editor has a "Size inspector" that looks like a ruler icon near the top right of the Xcode window. That allows you to specify the size and location of a view inside its parent view. There are also controls that determine what happens to the subview when its parent changes size...on rotation, for example.

    You can make a view into a subview either by dragging it into the parent in the layout section of the editor screen or by arranging views in the hierarchy window under "Objects".