zoukankan      html  css  js  c++  java
  • iOS 如何在Label中显示html的文本

    if (self.messageModel) {
            
            NSString * htmlString = self.messageModel.contentText;
            NSAttributedString * attrStr1 = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];  //就这句有用
            
            self.messageTextView.attributedText = attrStr1;
            
            if (1) {
                NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"【重要】"];
                 [attrStr appendAttributedString:attrStr1];
                NSRange range = NSMakeRange(0, 4);
                [attrStr addAttribute:NSForegroundColorAttributeName value:GNHGreenColor range:range];
                self.messageTextView.attributedText = attrStr;
            }
        }

    显示如下:

  • 相关阅读:
    MySQL 连接的使用
    MySQL GROUP BY 语句
    MySQL 排序
    MySQL UNION 操作符
    MySQL LIKE 子句
    MySQL DELETE 语句
    MySQL UPDATE 更新
    MySQL WHERE 子句
    php MySQL 查询数据
    MySQL 插入数据
  • 原文地址:https://www.cnblogs.com/lyz0925/p/5974432.html
Copyright © 2011-2022 走看看