美文网首页
UIAlertController 显示HTML标签字符串

UIAlertController 显示HTML标签字符串

作者: Heikki_ | 来源:发表于2019-04-08 14:17 被阅读0次
效果图
HTML字符串如下

"可提现余额是指用户进行IC智库明确规定的可提现操作后<font color='#999999'>(如邀请认证、上传付币视频被购买、回答付币问题)</font>所获得的酷币,该酷币可按<font color='#004e83'>1酷币=0.1人民币</font>的汇率进行提现,最终解释权归----所有"

1.html标签格式转化成 NSAttributedString
let htmlData = NSString(string: alertMsg).data(using: String.Encoding.unicode.rawValue)

let options = [NSAttributedString.DocumentReadingOptionKey.documentType:
    NSAttributedString.DocumentType.html]

let attributedString = try? NSMutableAttributedString(data: htmlData ?? Data(),
                                                      options: options,
                                                      documentAttributes: nil)
2.UIAlertController显示 NSAttributedString
let alertController = UIAlertController(title: "提现余额说明", message: "", preferredStyle: UIAlertControllerStyle.alert)

alertController.setValue(attributedString, forKey: "attributedMessage")

let action = UIAlertAction(title: "确认", style: .default, handler: { (_) in
    
})

alertController.addAction(action)

self.present(alertController, animated: true, completion: nil)

参考

相关文章

网友评论

      本文标题:UIAlertController 显示HTML标签字符串

      本文链接:https://www.haomeiwen.com/subject/jfbuiqtx.html