zoukankan      html  css  js  c++  java
  • 让Label等控件支持HTML格式的代码? 使用NSAttributedString:

    > 如何让Label等控件支持HTML格式的代码? 使用NSAttributedString:

    NSString *htmlString = @"<div>Tate<span style='color:#1C86EE;'>《iOS Develop Tips》</span>get <span style='color:#1C86EE;'>Tate_zwt</span> 打赏 <span style='color:#FF3E96;'>100</span> 金币</div>";
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType } documentAttributes:nil error:nil];_contentLabel.attributedText = attributedString;

    >如何让Label等控件同时支持HTML代码和行间距?

    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithData:[_open_bonus_article dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];[paragraphStyle setLineSpacing:12]; //调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [attributedString length])];
    _detailLabel.attributedText = attributedString;[_detailLabel sizeToFit];
     


    链接:http://www.jianshu.com/p/02588a132e22

  • 相关阅读:
    Swift中函数
    Swift 中的开关语句switch在swift中的使用
    Swift 函数新特性
    Swift 学习-多线程
    安卓学习
    ios -网络
    ios 中block
    Lua 简易调试
    iOS、Cocos2dx、Unity3D下的坐标系统简介
    Lua开发过程中遇到的一些小问题
  • 原文地址:https://www.cnblogs.com/isItOk/p/7273998.html
Copyright © 2011-2022 走看看