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

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

作者: VickyLanLan | 来源:发表于2022-03-24 14:13 被阅读0次

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

    }

    相关文章

      网友评论

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

          本文链接:https://www.haomeiwen.com/subject/avifjrtx.html