带有`center`标签的NSAttributed字符串不起作用

时间:2015-04-28 09:08:32

标签: html ios iphone nsattributedstring

我试图通过传递字符串检查下面的方法将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以外的任何方式?

  

无论如何,我不想将NSTextAlignmentCenter属性设置为   的UILabel。

提前致谢...

1 个答案:

答案 0 :(得分:1)

通过将<{1}}标记替换为

来解决

<center>

来自w3schools

,HTML5中不再支持

enter image description here