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)