Swift HTML富文本显示
来源:互联网 发布:淘宝一颗钻多少钱 编辑:程序博客网 时间:2024/06/06 11:46
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)); }
阅读全文
0 0
- Swift HTML富文本显示
- Swift笔记 label 显示富文本或HTML
- 解析html富文本
- 使用UIWebView中html标签显示富文本
- iOS UILabel 显示带有html标签的富文本内容
- 微信小程序Markdonw、HTML富文本内容显示解决办法
- TextView富文本显示
- UILabel显示富文本
- qlistview 显示富文本
- Swift 3.0 label富文本
- Swift 富文本属性设置
- V5富文本和HTML
- UILabel展示html富文本
- UIWebView展示html富文本
- 富文本Html.fromHtml方法
- iOS 富文本加载 HTML
- 富文本编辑器html过滤
- 用TextView显示富文本
- Windows10 64位安装MySQL5.6.35
- Qt 所有权问题导致多线程报错
- gulp顺序执行任务
- 负载均衡配置,
- ubuntu的Files资源管理器打不开解决方案
- Swift HTML富文本显示
- 多语言切换
- java线程安全的单利模式
- 水波纹-iOS
- 数字证书申请流程
- Spring Boot学习笔记-整合Mybatis (三)
- leetcode-第十四周
- Android Handler 机制
- DHCP服务器安装、测试