带有“center”标签的 NSAttributedstring 不起作用

NSAttributed string with `center` tag is not working

我正在尝试通过传递字符串检查以下方法将 NSAttributed 字符串设置为 UILabel:

-(NSAttributedString *) returnRichTextForString:(NSString *) inputString {

   NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[inputString dataUsingEncoding:NSUTF8StringEncoding]  options:@{NSDocumentTypeDocumentAttribute:  NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
   NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
   [paragrahStyle setLineBreakMode:NSLineBreakByTruncatingTail];
   [attributedString addAttribute:NSParagraphStyleAttributeName value:paragrahStyle range:NSMakeRange(0, [attributedString length])];
   return attributedString; 
}

我将输入字符串作为: @"<body> <p>This is some text.</p> <center>This text will be center-aligned.</center> <p>This is some other text. </p> </body>";

我希望 <center>...</center> 标记内的文本居中对齐。但它没有发生! CSS 以外的任何方式?

Anyway I don't want to set NSTextAlignmentCenter attribute to UILabel.

提前致谢...

通过将 <center> 标签替换为

解决

<div style="text-align:center">...</div>

来自 w3schools 在 HTML5

中不再受支持