title: iOS: UIButton resize according to text length
body: <p>In interface builder, holding <kbd>Command</kbd> + <kbd>=</kbd> will resize a button to fit its text. I was wondering if this was possible to do programmatically before the button was added to the view. </p>
  
  <pre><code>UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  [button.titleLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:12]];
  [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
  // I need to know the width needed to accomodate NSStringVariable
  [button setTitle:NSStringVariable forState:UIControlStateNormal]; 
  // So that I can set the width property of the button before addSubview
  [button setFrame:CGRectMake(10, 0, width, fixedHeight)];
  [subNavigation addSubview:button];
  </code></pre>