您的当前位置:首页正文

html字符串转oc字符串

来源:图艺博知识网

这周在项目中遇到了从服务器返回的数据中有html字符串,举个栗子<font color=#1A6D99>TST: </font><font color=black>gg</font>,当时sha呵呵的遍历整个字符串去掉标签然后自己处理,弄到晚上9点多总觉得不对.....

oc中有处理的方法

NSString *string = @"<font color=#1A6D99>TST: </font><font color=black>gg</font>"; NSAttributedString* attrStr = [[NSAttributedStringalloc] initWithData:[string dataUsingEncoding:NSUnicodeStringEncoding]options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}documentAttributes:nilerror:nil]; UILabel *contentLabel.attributedText = attrStr;

Top