title: How can I horizontally center a single line of text in UITextView?
body: <p>I have a UITextView which displays a fair amount of text. I need to horizontally center some, but not all, of the lines of text in the text view. </p>
  
  <p>I've tried setting the <code>NSParagraphStyleAttributeName</code> with an NSParagraphStyle instance whose <code>alignment</code> property is <code>NSTextAlignmentCenter</code> on the range of the line to be centered. I'm also setting the font so the centered line is bold. When I do this using the code below, the relevant line is bolded, but remains left aligned.</p>
  
  <pre><code>if (shouldCenterLine) {
      NSMutableParagraphStyle *centerStyle = [[NSMutableParagraphStyle alloc] init];
      centerStyle.alignment = NSTextAlignmentCenter;
      NSDictionary *attributes = @{NSParagraphStyleAttributeName : centerStyle,
                                   NSFontAttributeName : boldFont};
      [attributedString setAttributes:attributes range:lineRange];
  }
  </code></pre>
  
  <p>If I apply this same paragraph style attribute to the entire contents of the text view, the text ends up centered as expected.</p>
  
  <p>Is it possible to convince <code>UITextView</code> to center specific subranges of its text? Is the only solution to move to a <code>UIWebView</code> rendering generated HTML? Note that this is for an app still supporting iOS 6, so unfortunately I'm not able to use Text Kit.</p>