【发布时间】:2013-11-24 04:14:25
【问题描述】:
我正在尝试获取 html 格式的文本 sn-p,以便在 iPhone 上的 UITableViewCell 中很好地显示。
到目前为止,我有这个:
NSError* error;
NSString* source = @"<strong>Nice</strong> try, Phil";
NSMutableAttributedString* str = [[NSMutableAttributedString alloc] initWithData:[source dataUsingEncoding:NSUTF8StringEncoding]
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]}
documentAttributes:nil error:&error];
这种作品。我收到一些带有“Nice”粗体字的文字!但是...它还将字体设置为 Times Roman!这不是我想要的字体。 我想我需要在 documentAttributes 中设置一些东西,但是,我在任何地方都找不到任何示例。
【问题讨论】:
-
注意:NSHTMLTextDocumentType 可能会很慢。见stackoverflow.com/questions/21166752/…
-
重要提示:如果您使用自定义字体,您需要查看此答案stackoverflow.com/a/60786178/1223897
标签: html ios nsattributedstring