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富文本显示所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)