title: How to align a subview to the center of a parent NSView
body: <p>I'm developing a program in which I am programmatically adding an NSImageView to a custom NSView class. While creating the image-view, I am passing the frame of the parent container.</p>
  
  <pre><code>-(NSImageView *)loadNSImage:(NSString *)imageName frame:(NSRect)frame{
      imageName = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
      NSImage *image = [[NSImage alloc] initWithContentsOfFile:imageName]; 
      NSImageView *imageView = [[NSImageView alloc]initWithFrame:frame];
      [imageView setImage:image];
      [imageView setImageScaling:NSImageScaleProportionallyUpOrDown];
      [imageView setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable | NSViewMaxXMargin | NSViewMaxYMargin | NSViewMinXMargin | NSViewMinYMargin];
      [imageView setImageAlignment:NSImageAlignCenter];
      [image release];
      return imageView;
  }
  </code></pre>
  
  <p>Then I am using the <code>addSubView</code> method to add this into the Custom View. The problem is that the image sticks to the bottom-left of the parent view. How can I place this image in the center of the parent view?</p>
  
  <p>I have tried adding an offset to the frame origin, but that doesn't really work when the window is resized, or if an image with a different size is loaded.</p>
  
  <p>Any help would be appreciated.</p>