title: How to load custom UIView from xib file into a UIView in UIViewController?
body: <p>I created a xib file.
  <a href="https://i.stack.imgur.com/OaI6O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OaI6O.png" alt="enter image description here"></a></p>
  
  <p>Below is the code:</p>
  
  <pre><code>#import "LoginView.h"
  @implementation LoginView
  
  -(id)initWithFrame:(CGRect)frame{
  self = [super initWithFrame:frame];
  if (self) {
      // Initialization code
      [self setup];
  }
  return self;
  }
  
  -(void) setup{
  [[NSBundle mainBundle] loadNibNamed:@"LoginView" owner:self options:nil];
  
  self.bounds = self.loginView.bounds;
  
  [self addSubview:self.loginView];
  }
  </code></pre>
  
  <p>Now I created a view controller and add a UIView to it. In viewWillAppear, I am trying to load the xib file into a defined UIView in my view controller.</p>
  
  <pre><code>-(void)viewWillAppear:(BOOL)animated{
  self.containerView.layer.borderColor = [UIColor blackColor].CGColor;
  self.containerView.layer.borderWidth = 2.0f;
  LoginView *loginView = [[LoginView alloc] initWithFrame:CGRectMake(self.containerView.frame.origin.x,self.containerView.frame.origin.y, self.containerView.frame.size.width, self.containerView.frame.size.height)];
  [self.containerView addSubview:loginView];
  }
  </code></pre>
  
  <p>But, the xib file is going outside the defined UIView which I named containerView. I have linked the containerView to UIView in ViewController.</p>
  
  <pre><code>@property(nonatomic, weak) IBOutlet UIView *containerView;
  </code></pre>
  
  <p>Can anyone help me why I am getting this output? I need to get the custom uiview inside the containerView in ViewController. Like the textfields and buttons should be inside the black border.</p>
  
  <p><a href="https://i.stack.imgur.com/ZdFx6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZdFx6.png" alt="enter image description here"></a></p>