title: iOS NSAttributedString on UIButton
body: <p>I'm using <strong>iOS 6</strong>, so attributed strings should be easy to use, right? Well... not so much.</p>
  
  <p>What I want to do:</p>
  
  <p>Using a custom subclass of <code>UIButton</code> (it doesn't do anything custom to <code>titleLabel</code>), I'd like to have a multi-line, attributed title that is:</p>
  
  <ol>
  <li>All caps (I realize that's not part of the attributes) on the first line</li>
  <li><strong>Bolded</strong> on the first line</li>
  <li><strong>Underlined</strong> on the first line</li>
  <li>"Normal" weight on the second line</li>
  <li>Non-underlined on the second line</li>
  <li>Centered on both lines</li>
  </ol>
  
  <p>I've been able to get #'s 1 through 5 so far (at least, I thought I did, but current testing is yielding errors with multi-line text), but when I tried to do something (anything!) to get the text to be centered, my app keeps crashing. When I try to get all 6 items working (through various methods), I get the following crash/error:</p>
  
  <pre><code>Terminating app due to uncaught exception 
  'NSInternalInconsistencyException', reason: 
  'NSAttributedString invalid for autoresizing, 
  it must have a single spanning paragraph style
  (or none) with a non-wrapping lineBreakMode.'
  </code></pre>
  
  <p>Based on what I've tried, it appears that I can have one of the following options, but not both:</p>
  
  <ol>
  <li>A multi-line, centered label</li>
  <li>An attributed label</li>
  </ol>
  
  <p>I can live with one or the other if I <strong>must</strong>, but I can't believe that I can't have what seems to be a fairly straightforward concept.</p>
  
  <p>Can someone please tell me what I've got wrong?</p>
  
  <p>Here's the last iteration of the code I'm trying:</p>
  
  <pre><code>NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
  [style setAlignment:NSTextAlignmentCenter];
  [style setLineBreakMode:NSLineBreakByWordWrapping];
  
  UIFont *font1 = [UIFont fontWithName:@"HelveticaNeue-Medium" size:20.0f];
  UIFont *font2 = [UIFont fontWithName:@"HelveticaNeue-Light"  size:20.0f];
  NSDictionary *dict1 = @{NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),  
                          NSFontAttributeName:font1};
  NSDictionary *dict2 = @{NSUnderlineStyleAttributeName:@(NSUnderlineStyleNone),    
                          NSFontAttributeName:font2};
  
  NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] init];
  [attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"LINE 1\n"    attributes:dict1]];
  [attString appendAttributedString:[[NSAttributedString alloc] initWithString:@"line 2"      attributes:dict2]];
  [[self buttonToStyle] setAttributedTitle:attString forState:UIControlStateNormal];
  [[[self buttonToStyle] titleLabel] setNumberOfLines:0];
  [[[self buttonToStyle] titleLabel] setLineBreakMode:NSLineBreakByWordWrapping];
  </code></pre>