答案 0 :(得分:0)
I don't think it is a perfect answer here, just a half proof.
I add some sample code here:
let text = NSMutableAttributedString.init(string: "hello")
let range = NSMakeRange(0, text.length)
// add large fonts
text.addAttribute(NSAttributedString.Key.backgroundColor, value: UIColor.red, range: range)
text.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor.blue, range: range)
text.addAttribute(NSAttributedString.Key.font, value: UIFont.systemFont(ofSize: 72), range: range)
// add underline
text.addAttribute(NSAttributedString.Key.underlineStyle, value: NSNumber(value: NSUnderlineStyle.double.rawValue), range: range)
text.addAttribute(NSAttributedString.Key.underlineColor, value: UIColor.green, range: range)
textView.attributedText = text