iOS 后台返回的数据是标签 Html转换成文字

-(void)setContent:(NSString*)content {

    _content=content;

    _attributedTitle = [self createAttributedWithString:content font:LYFont(Scale(Font16)) color:@"#303133"];

}

- (NSMutableAttributedString *)createAttributedWithString:(NSString *)str font:(UIFont*)strFont color:(NSString *)color{

   NSMutableAttributedString  *attrString = [[NSMutableAttributedString alloc] initWithString:@""];

   if(str && strFont){

       str = [selfcompareWithHtlmColor:strcolor:color];

       attrString =  [[NSMutableAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

       NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc]init];


       style.lineBreakMode = NSLineBreakByTruncatingTail;

       [attrStringaddAttribute:NSFontAttributeName value:strFont range:NSMakeRange(0, attrString.length)];

       [attrStringaddAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attrString.length)];

   }

   returnattrString;

}

- (NSString*)compareWithHtlmColor:(NSString*)strcolor:(NSString*)color{

   return [NSString stringWithFormat:@"

%@
",color,str];

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容