Swift HTML富文本显示

Swift HTML富文本显示,第1张

概述iOS平台下更灵活 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. var strHtml = "<html><body> Hello <span

iOS平台下更灵活

    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        // Do any additional setup after loading the vIEw,typically from a nib.        var strHTML = "<HTML><body> Hello <span style=\"color:#0f0;Font-size:30px;\">It is me.</span>"        strHTML += "<br/> <Font size=\"13\" color=\"red\">Here you are,Here we are!</Font>;</body></HTML>";                let label:UILabel = UILabel()        label.text = strHTML        label.numberOflines = 0 //line break when the current line is full display.        label.lineBreakMode = NSlineBreakMode.byClipPing;//Tips:Supported six types.                do{            let srtData= strHTML.data(using: String.EnCoding.unicode,allowLossyConversion: true)!            let strOptions = [NSdocumentTypedocumentAttribute: NSHTMLTextdocumentType]//Tips:Supported four types.            let attrStr = try NSAttributedString(data: srtData,options: strOptions,documentAttributes: nil)            label.attributedText = attrStr        }catch let error as NSError {            print(error.localizedDescription)        }        label.frame = CGRect(x:self.vIEw.frame.origin.x,y:self.vIEw.frame.origin.y,wIDth:self.vIEw.frame.size.wIDth,height:self.vIEw.frame.size.height);        self.vIEw.addSubvIEw(label)    }
androID平台下更直接
@OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main);        String strHTML = "<HTML><body> Hello,<span style=color:#0f0;Font-size:30;>It is me.</span>";        strHTML += "<br/> <Font size=13 color=red>Here you are,Here we are!</Font>;</body></HTML>";        TextVIEw textVIEw = (TextVIEw)findVIEwByID(R.ID.text);        textVIEw.setText(HTML.fromHTML(strHTML));    }
总结

以上是内存溢出为你收集整理的Swift HTML富文本显示全部内容,希望文章能够帮你解决Swift HTML富文本显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1062818.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存