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 dire
The issue is that as said by the doc initWithData:options:documentAttributes:error: only accept 3 possibles keys: NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute and NSDefaultAttributesDocumentAttribute.
Then, with your snippet, you didn't applied the NSParagraphStyleAttributedName at the end like in your previous attempt.
So, from your snippet, I put this line instead:
[attributedText addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, attributedText.length)];
And removed the 2 useless attributed from attr:
NSDictionary *attr = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)};
Well, I found a solution. I assume the alignment doesn't work because it expects this kind of attributes in the html. So I added it to the html:
text = [@"<style> p {text-align: right;}</style><body>" stringByAppendingFormat:@"<p>%@</p></body>", text];
Works with center, left, etc.