title: NSAttributedString alignment not working on html content
body: <p>Want to change alignment of html label. Nothing works. I don't see any CSS in the HTML. There are no further settings changing the alignment. I also set left alignment directly on the UILabel. What am I missing? </p>
  
  <p>The code is in UILabel extension.</p>
  
  <pre><code>NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
  paragraphStyle.alignment = NSTextAlignmentLeft;
  
  NSDictionary *attr = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,  NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding), NSParagraphStyleAttributeName: paragraphStyle};
  NSError *error = nil;
  
  NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc]initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:attr documentAttributes:nil error:&amp;error];
  
  // also tried with this
  [attributedText addAttribute:NSParagraphStyleAttributeName value:paragraphStyle
                             range:NSMakeRange(0, html.length)
       ];
  
  self.attributedText = attributedText;
  </code></pre>
  
  <p><strong>Edit</strong></p>
  
  <p>Ok, so I created a separate project and there, the text is left aligned by default. I have to find out why in above example the text shows justified. In any case, the main problem remains, I can't change the default alignment. It works when initializing the attributed string with <code>initWithString</code>. But in this case html doesn't work. When <code>initWithData</code>, like in above example, html works but alignment does not work.</p>
  
  <p>Run this snippet and you will see.</p>
  
  <pre><code>UILabel *label = [[UILabel alloc] init];
  label.frame = CGRectMake(50, 50, 300, 400);
  label.backgroundColor = [UIColor yellowColor];
  label.numberOfLines = 0;
  label.textAlignment = NSTextAlignmentRight;
  
  NSString *text = @"sfsf sldjfs fj &lt;b&gt;dsfjslf&lt;/b&gt; dsfslkf jsfsfjsdkfsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkflsfsf sldjfs fj dsfjslf dsfslkf jsfsfjsdkfll END";
  
  NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
  paragraphStyle.alignment = NSTextAlignmentRight;
  
  UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:14];
  NSDictionary *attr = @{
                         NSFontAttributeName: font,
                         NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                         NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding), 
                         NSParagraphStyleAttributeName: paragraphStyle};
  NSError *error = nil;
  
  NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc]initWithData:[text dataUsingEncoding:NSUTF8StringEncoding] options:attr documentAttributes:nil error:&amp;error];
  
  [attributedText addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, attributedText.length)];
  
  NSLog(@"err: %@", error);
  
  label.attributedText = attributedText;
  
  [self.view addSubview:label];
  </code></pre>
  
  <p>Edit 2:</p>
  
  <p>Case 1 - solved - I somewhere later in the code alignment was being changed. Didn't see that.</p>
  
  <p>Case 2 - solved - see answer.</p>