title: why is my UIView subview not rendering within the parent? (code attached)
body: <p>Why is my custom <code>UIView</code> not rendering within the <code>UIView</code> container of it's parent?  So what I have is:</p>
  
  <ul>
  <li>MainViewController - has a <code>UIView</code> "<code>customViewContainer</code>" (which doesn't take up the whole screen), and</li>
  <li>CustomView - is a <code>UIView</code> with a XIB file - it is the <code>UIView</code> here that when it is rendered (with AspectFit) is rendering outside the bounds of the parent "<code>customViewContainer</code>"</li>
  </ul>
  
  <p>The code used to setup the custom view is this extract from MainViewController:</p>
  
  <p>&lt;&lt; cut - see Update2 below >></p>
  
  <p>So I can't see why the <code>CustomView</code> view is being rendered in a way that is larger in area than the parent <code>customViewContainer</code>?   What I want is for the <code>customview</code> to fit into the parent "<code>customViewContainer</code>" entirely per the <code>AspectFit</code> type approach.</p>
  
  <p>thanks</p>
  
  <p><strong>EDIT 1</strong> (added clarification) - If I "clip subviews" in the parent view then it does then clip things, but what I really need to render the custom view within the parent view area (not the whole area of the screen).  So I need (a) the center of the custom view to be in the center of the parent view, and (b) custom view to AspectFit into the parent view properly.  Any ideas?</p>
  
  <p><strong>EDIT 2</strong> - Update</p>
  
  <p>sorry - made a copy/paste mistake with code in the original question  - can't seem to edit it so I'll put a correct version below - so to clarify:</p>
  
  <p><code>MainViewController</code> - has a <code>UIView</code> "<code>containerView</code>" (which doesn't take up the whole screen), and <code>CustomView</code> - is a <code>UIView</code> with a XIB file - it is the <code>UIView</code> here that when it is rendered (with <code>AspectFit</code>) is rendering outside the bounds of the parent "<code>containerView</code>"</p>
  
  <p>With the code below does this make sense now?  The reason for this code is I have a custom <code>UIView</code>, BUT I have a XIB file associated with it, so this was the only way to get my <code>MainController</code> view to be able to use it.  That is, have a container view in the <code>MainController</code> <code>view</code>, and then programmatically add the <code>CustomView</code> into the container view.</p>
  
  <p>Re "So set the frame or center of the view that you're adding to be what you want it to be" - are you saying I have to programmatically/manually set the dimension of the CustomView to be what I want (in relation to the parent containerView)?  </p>
  
  <p>What I was hoping was there was a way using the declaritive layout setting to some how be able to say "Load the Custom View from it's XIB file, and the aspectFit this view into the self.containerView", however I'm starting to wonder if this is possible?</p>
  
  <p>UPDATED CODE BELOW (made mistake in original question when I copy/pasted it in and changed variables names etc)</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      // Load the custom Altimeter View into this UIControllerView's container UIView for it
      NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"Customview" owner:self options:nil];
      for (NSObject *obj in nibs) {
          if ( [obj isKindOfClass:[Customview class]]) {
              Customview *cv = (Customview*)obj;
              [self.containerView addSubview:cv];
              break;
          }
      }
      // UI Layout
      self.containerView.layer.borderWidth = 2;
      self.containerView.layer.borderColor = [[UIColor redColor] CGColor];
  }
  </code></pre>