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

2022-03-24  本文已影响0人  VickyLanLan

-(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];

}

上一篇下一篇

猜你喜欢

热点阅读