【发布时间】:2016-02-23 17:16:31
【问题描述】:
HTML 文本:
<span style="color: rgb(158, 29, 255);"><b>This</b> is a <i>simple</i> <u>text</u>.</span>
输出:
这个是一个简单的 文本。
这是我将 HTML 文本转换为属性字符串的代码:
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init] ;
[paragraphStyle setAlignment:NSTextAlignmentCenter];
NSAttributedString *attributedString = [[NSAttributedString alloc]
initWithData:[@"<span style="color: rgb(158, 29, 255);"><b>This</b> is a <i>simple</i> <u>text</u>.</span>" dataUsingEncoding:NSUnicodeStringEncoding]
options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,NSParagraphStyleAttributeName:paragraphStyle}
documentAttributes:nil error:nil];
但是,它没有将属性字符串设置为居中对齐。怎么了?
【问题讨论】:
-
您不能将
NSParagraphStyleAttributeName与initWithData:options:documentAttributes:error:一起使用。之后添加。