title: UILabel set to center of view
body: <p>How come the <code>UILabel</code> drawn in this code is not in the center of the <code>view</code>?</p>
  <pre><code>//create the view and make it gray
  UIView *view = [[UIView alloc] init];
  view.backgroundColor = [UIColor darkGrayColor];
  
  //everything for label
  UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,42,21)];
  
  //set text of label
  NSString *welcomeMessage = [@&quot;Welcome, &quot; stringByAppendingString:@&quot;username&quot;];
  welcomeMessage = [welcomeMessage stringByAppendingString:@&quot;!&quot;];
  label.text = welcomeMessage;
  
  //set color
  label.backgroundColor = [UIColor darkGrayColor];
  label.textColor = [UIColor whiteColor];
  
  //properties
  label.textAlignment = NSTextAlignmentCenter;
  [label sizeToFit];
  
  //add the components to the view
  [view addSubview: label];
  label.center = view.center;
  
  //show the view
  self.view = view;
  </code></pre>
  <p>The line, <code>label.center = view.center;</code> should move the <code>label</code> to the center of the <code>view</code>. But instead moves it to where the center of the <code>label</code> is in the left hand corner of the <code>view</code> as shown below.</p>
  <p><a href="https://i.stack.imgur.com/rbJgw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rbJgw.png" alt="screenshot" /></a><br />
  <sub>(source: <a href="http://gyazo.com/2d1c064a671e32c7eb004647232fa430.png" rel="nofollow noreferrer">gyazo.com</a>)</sub></p>
  <p>Does anyone know why?</p>