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;
            }
        }

    显示如下:

  • 相关阅读:
    历史版本xcode的下载
    mac上安装hg
    xcode不能抓帧
    window buffer alignment
    highp 和 mediump
    AFBC mali
    AO composition
    gpu memory wait
    L2 cache//bifrost --- cortex-A55
    效果样式
  • 原文地址:https://www.cnblogs.com/lyz0925/p/5974432.html
Copyright © 2011-2022 走看看